Pick-up Sticks
Time limit1sMemory limit128 MB
Given line segments thrown in order, report the segments not crossed by any later segment, using segment intersection tests.
- Level
Medium7 of 10
- Topics
- Geometry, Brute force, Sorting, Implementation
- Solved
- No attempts yet
Problem
Stan has sticks of various lengths. He throws them onto the floor one at a time, in a random way. The sticks are so thin that their thickness can be ignored.
After he finishes throwing, Stan wants to find the top sticks — the sticks that have no other stick lying on top of them. A stick lies on top of a stick if was thrown after and the two sticks cross each other (touching at an endpoint counts as crossing). A stick is a top stick if none of the sticks thrown after it crosses it.
The last stick thrown is always on top. Find every stick that is on top.
Input
The input consists of several test cases. The first line of each case contains the number of sticks . Each of the next lines contains four real numbers , the planar coordinates of the two endpoints of one stick. The sticks are listed in the order in which Stan threw them. You may assume that there are no more than top sticks.
The input ends with a case where ; this case must not be processed.
Output
For each test case, print the top sticks on one line, in the order in which they were thrown, using the format:
Top sticks: a, b, c.
That is, print Top sticks: followed by the indices of the top sticks in throwing order, separated by , (a comma and a space), and end the line with a period .. The sticks are numbered in the order given in the input.