Earthquake Emendations
Time limit1sMemory limit128 MB
Match each scattered polygon piece to its rotated location in the shattered window schematic.
- Level
Medium6 of 10
- Topics
- Geometry, Hash map, Implementation
- Solved
- No attempts yet
Problem
A major earthquake has shattered a beautiful stained glass window in a college chapel, leaving colored glass pieces scattered across the floor. The window broke only along its lead joints, so every colored piece is completely intact. Each fallen piece lies either in its original orientation or rotated by a multiple of 90 degrees ( radians); no piece has been flipped over (mirrored).
Luckily, a schematic of the original window as it stood before the earthquake was found. From it you know that no two colored pieces of the window have the same shape and size. Using this schematic, write a program that identifies where each scattered piece belongs so the window can be reassembled.
Input
The input consists of several windows to reassemble, given one after another.
Each window begins with a line containing an integer (), the number of glass pieces in the window. The next lines each describe one distinct colored glass piece as a simple polygon with nonzero area. A polygon with vertices () is written as its vertices in counter-clockwise order, repeating the first vertex at the end to close it:
Within one polygon all vertices are distinct (that is, whenever ), and no three consecutive vertices are collinear. All coordinates are integers with .
After the piece descriptions comes one more line: the schematic of the original window, written as non-overlapping polygons concatenated together in the same format. Each schematic polygon is exactly one of the glass pieces above, rotated by a multiple of 90 degrees and then translated.
Windows may be separated by blank lines. A line containing a single marks the end of the input.
Output
For each window, output a single line. For the -th glass piece listed in the input (in the given order), print the position at which that piece appears in the schematic. Positions are numbered from , in the order the polygons occur in the schematic. Separate the numbers with single spaces.
Because no two pieces have the same shape and size, each piece matches exactly one schematic polygon, so this assignment is unique.