Decide whether two perpendicular lines split 4N mines into four groups of N and print the lexicographically smallest grouping.
Medium7GeometryBrute forceNo attempts yetTime limit5sMemory limit512 MBKing Tyrone and his four sons conquered the nation of Carrania. The sons started arguing about how to split the land right away, and the argument was really about the gold mines: no son was willing to end up with fewer mines than a brother.
There are 4N mines in all. The king spread out a map, drew one large X on it, and declared that each son would get one of the four pieces the X cuts the country into. The map he drew on was not a map of Carrania. His first minister hid that map and now has to draw the same kind of X on the real map so that every son gets the same number of mines. All four sons watched the king draw, so the borders must again be two perpendicular straight lines.
You are given the coordinates of the 4N mines. Decide whether two perpendicular lines can be drawn so that no mine lies on a border and each of the four regions holds exactly N mines.
Several pairs of lines can satisfy the condition, and two different pairs can cut the mines into the very same four groups, so report the division instead of the lines. Describe a division by a sequence g1,g2,…,g4N, where gi is the group of the i-th mine in input order. Number the groups 1,2,3,4 in the order in which they first appear in the sequence, so g1 is always 1. If more than one division is possible, print the sequence that is smallest in lexicographic order.
The first line has the number of test cases T. Each test case starts with a line holding N, the number of mines every son must get. The next 4N lines each hold two integers xi and yi, the coordinates of one mine. All mines sit at different positions and no three of them lie on one straight line.
Limits
For each test case print one line in the form Case #x: g_1 g_2 ... g_4N, where x is the test case number starting from 1 and the terms of the sequence are separated by single spaces. If no pair of perpendicular lines meets the condition, print Case #x: IMPOSSIBLE instead.