Falling Cards
Time limit1sMemory limit128 MB
Simulate a row of non-intersecting standing cards: when a card falls it sweeps a rectangle of height H, knocking over any card it touches, and each touched card topples away from the pusher.
- Level
Medium6 of 10
- Topics
- Geometry, Simulation, BFS
- Solved
- No attempts yet
Problem
Standing a playing card on its edge is hard, but someone patiently stood cards on a desk, each resting on its shorter edge. Seen from above, each card is a line segment on the desk; card runs from to . Every card has the same height , and no two segments intersect.
The first card is pushed and falls flat. As a card falls flat, its rectangular face covers a region of the desk: the base segment stays fixed, and the card covers the rectangle obtained by extending that segment a distance in the falling direction (perpendicular to the segment). Any still-standing card whose segment is touched by this rectangle also falls.
The first card falls in the direction obtained by rotating the vector by counter-clockwise.
When a falling card touches a standing card , card falls in whichever of the two directions perpendicular to its own segment makes the ray along its falling direction avoid crossing the line that contains card 's segment; that is, topples away from the card that pushed it.
The input never contains:
- a card that falls exactly perpendicular to the card that pushed it, or
- a falling card that touches more than one still-standing card.
Determine which cards fall and which remain standing.
Input
The first line contains the number of cards and the card height (, ; is a real number). Each of the next lines contains four real numbers , separated by spaces — the endpoint coordinates of card 's segment.
Output
Print the numbers of the cards that fall, in increasing order, separated by spaces.