Pick-up sticks
Problem descriptionstan has n sticks of various length. he throws them one at a time on the floor in a random way. after finishing throwing, Stan tries to find the top sticks, that is these sticks such that there is no stick on top of them. stan has noticed that the last thrown stick is always on top but he wants to know all the sticks that are on top. stan sticks are very, very thin such that their thickness can be neglected.
Inputinput consists of a number of instances. the data for each case start with 1 ≤ n ≤ 100000, the number of sticks for this case. the following n lines contain four numbers each, these numbers are the planar coordinates of the endpoints of one stick. the sticks are listed in the order in which Stan has thrown them. you may assume that there are no more than 1000 top sticks. the input is ended by the case with n = 0. this case shoshould not be processed. outputfor each input case, print one line of output listing the top sticks in the format given in the sample. the top sticks shocould be listed in order in which they were thrown.
The picture to the right below lower strates the first case from input. sample input
51 1 4 22 3 3 11 -2.0 8 41 4 8 23 3 6 -2.030 0 1 11 0 2 12 0 3 10
Sample output
Top sticks: 2, 4, 5.
Top sticks: 1, 2, 3.
Throwing a wooden stick to the ground in order gives the coordinates of the two endpoints of each wooden stick. Ask which sticks are not overwhelmed by other sticks. Output is required in order.
Analysis: two for loops are used to determine whether the current wooden stick is pressed by the backend. It is equivalent to the intersection of two line segments. Line Segment endpoint intersection is not considered.