Pick-up Sticks
Time Limit: 3000MS |
|
Memory Limit: 65536K |
Total Submissions: 11884 |
|
Accepted: 4499 |
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.
/*POJ 2653 segments intersect with segments to determine if the segment following the current segment intersects it hhh-2016-05-04 22:10:50*/#include <iostream> #include <vector># Include <cstring> #include <string> #include <cstdio> #include <queue> #include <cmath># Include <algorithm> #include <functional> #include <map>using namespace std; #define Lson (i<<1) #define Rson ((i<<1) | |) typedef LONG LONG ll;const int MAXN = 200000;double eps = 1e-8;int tot;int n,m;double x1,x2 , Y1,y2,x3,x4,y3,y4;int SGN (double x) {if (Fabs (x) < EPS) return 0; if (x < 0) return-1; else return 1;} struct point{double x, y; Point () {}, point (int _x,int _y) {x = _x,y = _y; } Point operator-(const point &b) const {return point (X-B.X,Y-B.Y); } double operator ^ (const point &b) const {return x*b.y-y*b.x; }};struct line{Point s,t; Line () {} line (point _s,point _t) {s = _s; t = _t; } int operator & (conSt Line&b) const {if (SGN (s-t) ^ (b.s-b.t) = = 0)//by cross product judgment {return 0; } return 1; }};bool Inter (line L1,line L2) {return max (l1.s.x,l1.t.x) >= min (l2.s.x,l2.t.x) && Max (l2.s.x, l2.t.x) >= min (l1.s.x,l1.t.x) && max (l1.s.y,l1.t.y) >= min (l2.s.y,l2.t.y) && Max (L2.S. Y,L2.T.Y) >= min (l1.s.y,l1.t.y) && sgn ((l2.s-l1.s) ^ (L1.T-L1.S)) *SGN ((l2.t-l1.s) ^ (l1.t-l1.s)) <= 0 &am p;& sgn ((l1.s-l2.s) ^ (L2.T-L2.S)) *SGN ((L1.T-L2.S) ^ (L2.T-L2.S)) <= 0;} int TANS[MAXN]; Line Line[maxn];int Main () {while (scanf ("%d", &n) && N) {memset (tans,1,sizeof (tans)); for (int i = 0; i < n; i++) {scanf ("%lf%lf%lf%lf", &x1,&y1,&x2,&y2); Line[i] = line (point (X1,y1), point (X2,y2)); } int num = n; for (int i = 0, i < n; i++) {for (int j = i+1; J < N; j + +) {if (Inter (Line[i],line[j])) {tans[i] = 0; num--; Break }}} int cur = 0; printf ("Top Sticks:"); for (int i = 0; i < n; i++) {if (Tans[i]) {cur++; if (num = = cur) printf ("%d.\n", i+1); else printf ("%d,", i+1); }}} return 0;}
POJ 2653 segments intersect with segments