Description
Stan 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.
Input
Input 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.
Output
For 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 without 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. there are N line segments, which are displayed on the coordinate axis in sequence. Ask those line segments that are not intersecting and output them in sequence. Idea: Use the line segment intersection method to traverse the Intersecting Line Segments in sequence. The remaining non-intersecting line segments are what the question asks. Note that the output format is pitted once;#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>using namespace std;struct point{ double x,y;};struct line{ point p1,p2;} a[100010];double chacheng (struct point p1,struct point p2,point p3){ return (p1.x-p3.x)*(p2.y-p3.y)-(p1.y-p3.y)*(p2.x-p3.x);}int judge(struct line l1,struct line l2){ if( min(l2.p1.x,l2.p2.x)<=max(l1.p1.x,l1.p2.x)&&min(l2.p1.y,l2.p2.y)<=max(l1.p1.y,l1.p2.y)&&min(l1.p1.x,l1.p2.x)<=max(l2.p1.x,l2.p2.x) &&min(l1.p1.y,l1.p2.y)<=max(l2.p1.y,l2.p2.y) &&chacheng(l1.p1,l2.p2,l2.p1)*chacheng(l1.p2,l2.p2,l2.p1)<=0 &&chacheng(l2.p1,l1.p2,l1.p1)*chacheng(l2.p2,l1.p2,l1.p1)<=0 ) return 1; else return 0;}int main(){ int n,i,j; int flag[100010]; while(~scanf("%d",&n)) { if(n==0) break; for(i=0; i<n; i++) scanf("%lf %lf %lf %lf",&a[i].p1.x,&a[i].p1.y,&a[i].p2.x,&a[i].p2.y); memset(flag,0,sizeof(flag)); for(i=0; i<n-1; i++) for(j=i+1; j<n; j++) if(judge(a[i],a[j])) { flag[i]=1; break; } printf("Top sticks: "); for(i=0; i<n; i++) if(flag[i]==0) { if(i==n-1) printf("%d.\n",i+1); else printf("%d, ",i+1); } } return 0;}
Zookeeper