1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include <stdio.h> #include <string.h> #include <math.h> #define MAX_N (100000 + 10) struct POS { double fX; double fY; };
POS begs[MAX_N], ends[MAX_N]; bool bAns[MAX_N]; int nN; const double fPrecision = 1e-8;
double Det(double fX1, double fY1, double fX2, double fY2) { return fX1 * fY2 - fX2 * fY1; }
double Cross(POS a, POS b, POS c) { return Det(b.fX - a.fX, b.fY - a.fY, c.fX - a.fX, c.fY - a.fY); }
int DblCmp(double fD) { if (fabs(fD) < fPrecision) { return 0; } else { return fD > 0 ? 1 : -1; } }
bool IsSegCross(int nI, int nJ) { return (DblCmp(Cross(begs[nI], ends[nI], begs[nJ])) ^ DblCmp(Cross(begs[nI], ends[nI], ends[nJ]))) == -2 (DblCmp(Cross(begs[nJ], ends[nJ], begs[nI])) ^ DblCmp(Cross(begs[nJ], ends[nJ], ends[nI]))) == -2; }
int main() { while (scanf("%d", &nN), nN) { for (int i = 1; i <= nN; ++i) { scanf("%lf%lf%lf%lf", &begs[i].fX, &begs[i].fY, &ends[i].fX, &ends[i].fY); }
memset(bAns, true, sizeof(bAns));
for (int i = 1; i < nN; ++i) { for (int j = i + 1; j <= nN; ++j) { if (IsSegCross(i, j)) { bAns[i] = false; break; } } }
printf("Top sticks:"); bool bPre = false; for (int i = 1; i <= nN; ++i) { if (bAns[i]) { if (bPre) { printf(","); } bPre = true; printf(" %d", i); } } printf(".\n"); }
return 0; }
|