A Classic Myth: Flatland Superhero
Time limit1sMemory limit128 MB
For each swarm of points, compute the minimum area of a parallelogram that contains all of them, using the rotating calipers method on the convex hull.
- Level
Hard8 of 10
- Topics
- Geometry, Divide and conquer, Math, Sorting
- Solved
- No attempts yet
Problem
Flatland needs a superhero! Recently, swarms of killer ants have been invading Flatland, and no one there can figure out how to stop these dastardly denizens. Fortunately, you — as a higher-dimensional being — have the chance to become a hero in the eyes of Flatland's citizens. Your job is to "freeze" each swarm of ants by trapping it inside a parallelogram.
For every swarm you must find an enclosing parallelogram of minimum area. Once a minimum-area parallelogram is placed around a swarm, the ants are effectively frozen in place and can no longer terrorize the inhabitants of the plane.
Write a program that, for each swarm, reports the area of its minimum-area enclosing parallelogram.
Input
The first line contains a single integer (), the number of ant swarms.
Each swarm is described as follows:
- A line with a single integer (), the number of ants in the swarm.
- lines follow, each giving the position of one ant as two numbers and (, ) separated by a space.
Within a single swarm, no two ants share the same location. Each swarm is handled independently of the others. All coordinates are given in fixed-point decimal notation with exactly four digits after the decimal point (for example, dddd.dddd). A swarm may admit several distinct parallelograms that all achieve the minimum area, but only that minimum area is asked for, so the answer is unique.
Output
For each swarm, print one line in the form:
Swarm i Parallelogram Area: A
where () is the swarm number and is the minimum area of an enclosing parallelogram for that swarm. Perform every computation with 64-bit IEEE floating-point numbers, and print in fixed-point decimal notation rounded to exactly four digits after the decimal point.