Pick-up sticks

时间:2022-02-20 17:24:44

Pick-up sticks

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 cases. 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 should 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 should be listed in order in which they were thrown.

The picture to the right below illustrates the first case from input.Pick-up sticks

Sample Input

5
1 1 4 2
2 3 3 1
1 -2.0 8 4
1 4 8 2
3 3 6 -2.0
3
0 0 1 1
1 0 2 1
2 0 3 1
0

Sample Output

Top sticks: 2, 4, 5.
Top sticks: 1, 2, 3.

Hint

Huge input,scanf is recommended.

题目大意,先后给出n条直线,求最后哪些直线上没有直线.

那么,由于n最大100000,所有肯定不能用普通的来.

其实,我们只要记录最上面的几条直线就行了,并且可以用动态数组来.毕竟只有100000条直线,却有可能有n个集合,也有可能只有1个,所有,用vector代替普通的数组是再好不过的了.

然而,数据实在太强,还是TLE了.然而...暴力加break优化却AC了!!!

 #include<cmath>
 #include<cstring>
 #include<cstdio>
 #include<algorithm>
 #include<vector>
 #define Vec point
 using namespace std;
 ;
 vector <int> que;
 int n;
 ];
 struct point{
     double x,y;
     void read(){scanf("%lf%lf",&x,&y);}
 }seg[][];
 :x>eps;}
 Vec operator + (point u,Vec v){
     Vec ret; ret.x=u.x+v.x,ret.y=u.y+v.y;
     return ret;
 }
 Vec operator - (point u,point v){
     Vec ret; ret.x=u.x-v.x,ret.y=u.y-v.y;
     return ret;
 }
 Vec operator * (Vec u,double v){
     Vec ret; ret.x=u.x*v,ret.y=u.y*v;
     return ret;
 }
 Vec operator / (Vec u,double v){
     Vec ret; ret.x=u.x/v,ret.y=u.y/v;
     return ret;
 }
 double cross(Vec u,Vec v){return u.x*v.y-u.y*v.x;}
 bool dotonseg(point P,point U,point V){
     ) ;
     ) ;
     ;
 }
 bool intersect(point P,point Q,point U,point V){
     &&fabso(cross(U-P,Q-P)*cross(V-P,Q-P))<) ;
     bool g1=dotonseg(P,U,V);
     bool g2=dotonseg(Q,U,V);
     bool g3=dotonseg(U,P,Q);
     bool g4=dotonseg(V,P,Q);
     ;
     ;
 }
 int main(){
     for (scanf("%d",&n); n; scanf("%d",&n)){
         memset(f,,sizeof f);
         ; i<=n; i++) seg[i][].read(),seg[i][].read();
         ; i<=n-; i++)
             ; j<=n; j++)
             ],seg[i][],seg[j][],seg[j][])){f[i]=; break;}
         printf("Top sticks:");
         ; i<n; i++) if (f[i]) printf(" %d,",i);
         printf(" %d.\n",n);
     }
     ;
 }