Description
Input
Output
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 #include <cmath> 6 using namespace std; 7 8 const double EPS = 1e-8; 9 10 inline int sgn(double x) { 11 return (x > EPS) - (x < -EPS); 12 } 13 14 struct Point { 15 double x, y; 16 Point() {} 17 Point(double x, double y): x(x), y(y) {} 18 void read() { 19 scanf("%lf%lf", &x, &y); 20 } 21 bool operator < (const Point &rhs) const { 22 if(y != rhs.y) return y < rhs.y; 23 return x < rhs.x; 24 } 25 Point operator + (const Point &rhs) const { 26 return Point(x + rhs.x, y + rhs.y); 27 } 28 Point operator - (const Point &rhs) const { 29 return Point(x - rhs.x, y - rhs.y); 30 } 31 Point operator * (const int &b) const { 32 return Point(x * b, y * b); 33 } 34 Point operator / (const int &b) const { 35 return Point(x / b, y / b); 36 } 37 double length() const { 38 return sqrt(x * x + y * y); 39 } 40 Point unit() const { 41 return *this / length(); 42 } 43 }; 44 typedef Point Vector; 45 46 double dist(const Point &a, const Point &b) { 47 return (a - b).length(); 48 } 49 50 double across(const Point &a, const Point &b) { 51 return a.x * b.y - a.y * b.x; 52 } 53 //ret >= 0 means turn left 54 double cross(const Point &sp, const Point &ed, const Point &op) { 55 return sgn(across(sp - op, ed - op)); 56 } 57 58 struct Seg { 59 Point st, ed; 60 Seg() {} 61 Seg(Point st, Point ed): st(st), ed(ed) {} 62 void read() { 63 st.read(); ed.read(); 64 } 65 }; 66 67 bool isIntersected(Point s1, Point e1, Point s2, Point e2) { 68 return (max(s1.x, e1.x) >= min(s2.x, e2.x)) && 69 (max(s2.x, e2.x) >= min(s1.x, e1.x)) && 70 (max(s1.y, e1.y) >= min(s2.y, e2.y)) && 71 (max(s2.y, e2.y) >= min(s1.y, e1.y)) && 72 (cross(s2, e1, s1) * cross(e1, e2, s1) >= 0) && 73 (cross(s1, e2, s2) * cross(e2, e1, s2) >= 0); 74 } 75 76 bool isIntersected(Seg a, Seg b) { 77 return isIntersected(a.st, a.ed, b.st, b.ed); 78 } 79 80 /*******************************************************************************************/ 81 82 const int MAXN = 100010; 83 84 Seg s[MAXN]; 85 bool isAns[MAXN]; 86 Point p; 87 int n; 88 89 int main() { 90 while(scanf("%d", &n) != EOF && n) { 91 memset(isAns, true, sizeof(isAns)); 92 for(int i = 0; i < n; ++i) s[i].read(); 93 for(int i = 0; i < n; ++i) 94 for(int j = i + 1; j < n; ++j) { 95 if(isIntersected(s[i], s[j])) { 96 isAns[i] = false; 97 break; 98 } 99 } 100 bool flag = false; 101 printf("Top sticks:"); 102 for(int i = 0; i < n; ++i) { 103 if(!isAns[i]) continue; 104 if(flag) printf(","); 105 else flag = true; 106 printf(" %d", i + 1); 107 } 108 puts("."); 109 } 110 }