The main topic: there is a stick, in order to arrange, to get out of the above is not the stick pressed by other sticks ....
Analysis: Can maintain a queue, if the stick is not pressed into the queue, if the judgment is pressed, let the pressure out of the queue, and finally put the stick in the queue, but not fast, the enumeration is the fastest ... It is said that there are no more than 1000 top sticks at any one time ..... It's hard to notice. The code is as follows:=========================================================================================================== ==========================
#include <stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<math.h>using namespacestd;Const intMAXN = 1e5+7;Const DoubleEPS = 1e-8;structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {} pointoperator- (ConstPoint &t)Const{ returnPoint (X-t.x, yt.y); } Double operator* (ConstPoint &t)Const{ DoubleAns = x*t.y-y*T.x; if(Ans > EPS)return 1; if(Fabs (ANS) < EPS)return 0; return-1; }};structsegment{Point A, B; Segment (Point A=0, point b=0): A (a), B (b) {}};BOOLIntersect (Segment A, segment B) {return(A.A-A.B) * (B.A-A.B) + (a.a-a.b) * (b.b-a.b) = =0;}intUSED[MAXN], ans[maxn];segment SEG[MAXN];BOOLFind (intKintN) { for(inti=k+1; i<=n; i++) { if(Intersect (Seg[k], seg[i]) &&Intersect (Seg[i], seg[k]))return true; } return false;}intMain () {intN; while(SCANF ("%d", &n)! = EOF &&N) { for(intI=1; i<=n; i++) {scanf ("%LF%LF%LF%LF", &seg[i]. A.x, &seg[i]. A.Y, &seg[i]. b.x, &Seg[i]. B.Y); Used[i]=false; } intk=0; for(intI=1; i<=n; i++) {Used[i]=Find (i, N); if(!used[i]) ans[k++] =i; } printf ("Top Sticks:"); for(intI=0; i<k-1; i++) printf ("%d,", Ans[i]); printf ("%d.\n", ans[k-1]); } return 0;}
Pick-up STICKS-POJ 2653 (segment intersection)