Analysis: each time a line segment is input, all the segments that have not been kicked and have intersections are kicked. The last part left is at the top.
[Cpp]
# Include <iostream>
# Include <string>
# Include <cstring>
# Include <algorithm>
# Include <cstdio>
# Include <cmath>
# Include <iomanip>
# Include <vector>
Using namespace std;
Const int maxn = 100000 + 100;
Struct point {
Double x, y;
Void read (){
Scanf ("% lf", & x, & y );
}
};
Struct line {
Point st, en;
Int k;
Void read (int I ){
K = I; st. read (); en. read ();
}
} Rt;
Double cross (point p0, point p1, point p2 ){
Return (p1.x-Snapshot X) * (p2.y-Snapshot y)-(p2.x-Snapshot X) * (p1.y-Snapshot y );
}
Int work (line a, line B ){
Double x = cross (a. st, a. en, B. st );
Double y = cross (a. st, a. en, B. en );
If (x * y <= 0) return 1;
Return 0;
}
Bool del (line x ){
If (work (x, Rt) & work (Rt, x) return true;
Return false;
}
Int main (){
Int n;
While (cin> n, n ){
Vector <line> M;
Vector <line>: iterator it;
For (int I = 1; I <= n; ++ I ){
Rt. read (I );
M. erase (remove_if (M. begin (), M. end (), del), M. end ());
M. push_back (Rt );
}
Printf ("Top sticks :");
For (it = M. begin (); it! = M. end (); ++ it ){
If (it + 1 = M. end ())
Cout <''<it-> k <'.' <endl;
Else cout <''<it-> k <',';
}
}
Return 0;
}
# Include <iostream>
# Include <string>
# Include <cstring>
# Include <algorithm>
# Include <cstdio>
# Include <cmath>
# Include <iomanip>
# Include <vector>
Using namespace std;
Const int maxn = 100000 + 100;
Struct point {
Double x, y;
Void read (){
Scanf ("% lf", & x, & y );
}
};
Struct line {
Point st, en;
Int k;
Void read (int I ){
K = I; st. read (); en. read ();
}
} Rt;
Double cross (point p0, point p1, point p2 ){
Return (p1.x-Snapshot X) * (p2.y-Snapshot y)-(p2.x-Snapshot X) * (p1.y-Snapshot y );
}
Int work (line a, line B ){
Double x = cross (a. st, a. en, B. st );
Double y = cross (a. st, a. en, B. en );
If (x * y <= 0) return 1;
Return 0;
}
Bool del (line x ){
If (work (x, Rt) & work (Rt, x) return true;
Return false;
}
Int main (){
Int n;
While (cin> n, n ){
Vector <line> M;
Vector <line>: iterator it;
For (int I = 1; I <= n; ++ I ){
Rt. read (I );
M. erase (remove_if (M. begin (), M. end (), del), M. end ());
M. push_back (Rt );
}
Printf ("Top sticks :");
For (it = M. begin (); it! = M. end (); ++ it ){
If (it + 1 = M. end ())
Cout <''<it-> k <'.' <endl;
Else cout <''<it-> k <',';
}
}
Return 0;
}