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
| #include<cstdio> #include<algorithm> using namespace std;
struct Point { int x, y; }; struct Line { Point a, b; }; inline int cross(Point& a, Point& b1, Point& b2) { int x1 = b1.x - a.x, y1 = b1.y - a.y; int x2 = b2.x - a.x, y2 = b2.y - a.y;
return x1*y2 - x2*y1; } inline bool intersect1D(int a1, int a2, int b1, int b2) { if (a1 > a2) swap(a1, a2); if (b1 > b2) swap(b1, b2);
return max(a1, b1) <= min(a2, b2); } inline bool intersect(Line& L1, Line& L2) { return intersect1D(L1.a.x, L1.b.x, L2.a.x, L2.b.x) && intersect1D(L1.a.y, L1.b.y, L2.a.y, L2.b.y) && cross(L1.a, L1.b, L2.a)*cross(L1.a, L1.b, L2.b) <= 0 && cross(L2.a, L2.b, L1.a)*cross(L2.a, L2.b, L1.b) <= 0; } Line line[13]; int main() { int Case; bool d[13][13] = {};
scanf("%d", &Case); while (Case--) { int n, i, j; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d%d%d%d", &line[i].a.x, &line[i].a.y, &line[i].b.x, &line[i].b.y);
for (i = 0; i < n; i++) for (j = 0; j < n; j++) d[i][j] = false; for (i = 0; i < n; i++) d[i][i] = true;
for (i = 0; i < n; i++) for (j = i + 1; j < n; j++) if (intersect(line[i], line[j])) d[j][i] = d[i][j] = true;
for (int k = 0; k < n; k++) for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (i != j&&d[i][k] && d[k][j] && !d[i][j]) d[i][j] = true;
while (scanf("%d%d", &i, &j) && i) puts(d[i - 1][j - 1] ? "CONNECTED" : "NOT CONNECTED"); if (Case) putchar('\n'); }
return 0; }
|