Protecting the Vegetables
Time limit2sMemory limit128 MB
Find the minimum-perimeter rectangle of any orientation that encloses all given points.
- Level
Medium7 of 10
- Topics
- Geometry, Sorting, Two pointers
- Solved
- No attempts yet
Problem
Sanggeun steals Seonyeong's vegetables. To stop him, Seonyeong decided to surround every vegetable with one fence. The price of a fence is proportional to its length, so she wants the shortest perimeter she can get. For reasons nobody understands, the fence can only be built in the shape of a rectangle.
Vegetables have no size and are drawn as points in the plane. Find the rectangle of minimum perimeter that holds every vegetable inside it or on its boundary.
Input
The input consists of several test cases. The first line of each test case has the number of vegetables (). Each of the next lines has two integers and (), the coordinates of one vegetable. No two vegetables share the same coordinates, and the vegetables of one test case never all lie on a single straight line.
The input runs to the end of the file.
Output
For each test case, print the minimum perimeter of the fence on a line of its own. The sides of the fence do not have to be parallel to the coordinate axes.
Round the perimeter at the seventh digit after the decimal point and print exactly six digits after the decimal point. A perimeter of exactly is printed as 4.000000. No input places the answer on a rounding boundary.