Invasion of the Boxes
Time limit1sMemory limit128 MB
Simulate a laser ray from the origin that destroys axis-aligned boxes and reflects off them, printing the order of destruction.
- Level
Medium6 of 10
- Topics
- Geometry, Simulation, Implementation
- Solved
- No attempts yet
Problem
You are under attack by a swarm of boxes. There are () boxes, and every box is an axis-aligned rectangle (its sides are parallel to the coordinate axes). To defend yourself, you have a giant laser.
The laser sits at the origin and fires a single beam in one fixed direction. When the beam meets a box, it destroys that box and reflects off it.
The reflection rule depends on where the beam first touches the box:
- If the first intersection point lies on a horizontal side of the box, the vertical component of the beam's direction is reversed.
- If the first intersection point lies on a vertical side of the box, the horizontal component is reversed.
- If the beam first strikes a corner of the box (where a horizontal side and a vertical side meet), both components are reversed.
A destroyed box disappears, so the beam may afterwards travel freely through the region that box used to occupy.
Report the indices of the destroyed boxes in the order in which they are destroyed.
It is guaranteed that no two boxes share any common point, and that no box contains the origin in its interior or on its boundary.
Input
The first line contains , the number of boxes.
The second line contains two integers and (, not both zero): a beam fired from the origin with nothing in its way passes through the point .
Each of the next lines contains four integers , , , and ( and ) describing the -th box, whose lower-left corner is and whose upper-right corner is . The boxes are numbered through in the order given.
Output
Let () be the number of boxes that are destroyed. Print lines; the -th line contains the index of the box destroyed on the -th bounce. If , print nothing.