Pick-up Sticks
Time Limit: 3000MS |
|
Memory Limit: 65536K |
Total Submissions: 11537 |
|
Accepted: 4337 |
Description
Stan has n sticks of various length. He throws them one at a time to the floor in a random. After finishing throwing, Stan tries to find the top sticks, that's these sticks such that there was no stick on top of th Em. Stan has noticed, the last thrown stick was always on top and he wants to know all the sticks that's on top. Stan sticks is very, very thin such that their thickness can be neglected.
Input
Input consists of a number of cases. The data for each case is start with 1 <= n <= 100000, and the number of the sticks for this case. The following n lines contain four numbers each, these numbers is the planar coordinates of the endpoints of one stick. The sticks is listed in the order in which Stan had thrown them. Assume that there is no more than top sticks. The input is ended by the case with N=0. This case is should not being processed.
Output
For each input case, print one line of output listing the top sticks in the format given in the sample. The top sticks should is listed in order in which they were thrown.
The below illustrates 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.
Hint
Huge input,scanf is recommended.
Source
Waterloo Local 2005.09.17
Ideas
Violent enumeration + determines whether segments intersect.
Data weak a beep ~ <_<
Code
1#include <cmath>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #definefor (A,B,C) for (int a= (b); a<= (c); a++)6 using namespacestd;7 8 Const intN =100000+Ten;9 Const DoubleEPS = 1e-8;Ten intDCMP (Doublex) { One if(x<eps)return 0;Else returnx<0? -1:1; A } - - structPt { the Doublex, y; -Pt (Doublex=0,Doubley=0): X (x), Y (y) {}; - }; - structLine {Pt a1,a2; + }; - typedef Pt VEC; +Vecoperator-(Pt a,pt B) {returnVEC (a.x-b.x,a.y-b.y); } A at DoubleCross (VEC A,vec B) {returna.x*b.y-a.y*b.x;} - - BOOLSeginter (PT S1, PT E1, PT S2, pt E2) { - if(Min (s1.x, e1.x) <= Max (s2.x, e2.x) && -Min (s1.y, e1.y) <= Max (s2.y, e2.y) && -Min (s2.x, e2.x) <= Max (s1.x, e1.x) && inMin (s2.y, e2.y) <= Max (S1.Y, E1.Y) && -Cross (E1-S1,S2-S1) * Cross (E1-S1,E2-S1) <=0&& toCross (E2-S2,S1-S2) * Cross (E2-S2,E1-S2) <=0 +)return true; - return false; the } * $ intN;Panax Notoginseng Line L[n]; - the intMain () { + while(SCANF ("%d", &n) = =1&&N) { A DoubleX,y,x2,y2; thefor (I,1, N) { +scanf"%LF%LF%LF%LF",&x,&y,&x2,&y2); -L[i].a1=pt (x, y), l[i].a2=Pt (x2,y2); $ } $ BOOLfirst=1; -printf"Top Sticks:"); -for (I,1, N) { the BOOLflag=1; -for (j,i+1, N)Wuyi if(Seginter (l[i].a1,l[i].a2,l[j].a1,l[j].a2)) { theflag=0; Break; - } Wu if(flag) { - if(first) first=0;ElsePutchar (','); Aboutprintf"%d", i); $ } - } -Puts"."); - } A return 0; +}
POJ Pick-up Sticks (judging segment intersection)