X Marks the Spot
Time limit5sMemory limit512 MB
Find the shortest integer direction so two movable perpendicular lines split the 4N points into four groups of N each.
- Level
Medium6 of 10
- Topics
- Geometry, Sorting, Brute force
- Solved
- No attempts yet
Problem
King Tyrone conquered the nation of Carrania, and his four sons immediately started to argue about how to split the land. The argument is about the gold mines. There are of them, and each son must end up with exactly .
The king draws an X on the map. The X is a pair of perpendicular straight lines that cuts the nation into four parts, one part per son. No gold mine may lie on a border, and each of the four parts must contain exactly gold mines.
The direction of the X is written as an integer vector . One border is a line with direction vector , and the other border is a line with direction vector . The minister may put the intersection point of the two borders anywhere.
A vector is good if the two perpendicular lines with these directions can be placed so that no gold mine lies on a border and each of the four parts holds exactly gold mines.
Turning a direction vector by degrees or flipping its sign gives the same X, so only vectors with , and are considered. Every X that has an integer direction vector has exactly one representative in this range.
Find the good vector with the smallest . If several good vectors share that value, take the one with the smallest .
Input
The first line contains the number of test cases . Each test case starts with a line containing , the number of gold mines each son must get. The next lines each contain two integers and , the coordinates of one gold mine.
Limits
- No three gold mines are collinear.
- A good vector with always exists.
Output
For each test case, print one line in the form Case #x: dx dy. Here is the test case number starting from , and and are the good vector with the smallest , with ties broken by the smallest .