Test instructions
There are n sticks that give the x, y coordinates of the two ends of the stick to determine if one of the two segments is connected (can be connected by another segment)
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath > #include <vector> #include <queue> #include <map> #include <algorithm> #include <set> using namespace std; #define MM (a) memset (A,0,sizeof (a)) typedef long Long ll;typedef unsigned long long ull;const int mod = 1000000007;const double EPS = 1e-10;const int inf = 0x3f3f3f3f;const int big=50000;int max (int a,int b) {return A>b?a: b;}; int min (int a,int b) {return a<b?a:b;}; int r[15];struct node{int x, y;} P;struct line{Node A, b;} Line[15];int Neiji (node A,node b) {return a.x*b.x+a.y*b.y;} int Jian (node A,node b,node c) {return (b.x-a.x) * (C.Y-A.Y)-(c.x-a.x) * (B.Y-A.Y);} int Findr (int i) {if (I!=r[i]) R[i]=findr (R[i]); return r[i];} void Unite (int i,int j) {int Ri=findr (i), Rj=findr (j); R[rj]=ri;} int solve (line m,line N) {if (min (m.a.x,m.b.x) <=max (n.a.x,n.b.x) && max (m.a.x,m.b.x) >=min (n.a.x,n.b.x ) &&Amp Min (m.a.y,m.b.y) <=max (N.A.Y,N.B.Y) && max (M.A.Y,M.B.Y) >=min (n.a.y,n.b.y) && Jian (m.a,m.b,n . a) *jian (m.a,m.b,n.b) <=0&& Jian (N.A,N.B,M.A) *jian (N.A,N.B,M.B) <=0) return 1; return 0;} Cross-stand experiment to judge the segment intersection int main () {int n; while (~SCANF ("%d", &n) &&n) {for (int i=1;i<=n;i++) scanf ("%d%d%d", &line[i].a.x,& AMP;LINE[I].A.Y,&LINE[I].B.X,&LINE[I].B.Y); for (int i=1;i<=n;i++) r[i]=i; for (int. i=1;i<=n;i++) for (int j=1;j<=n;j++)/* and check the connectivity of the segments, note that the two loops, each I will be directly connected to the collection where it is currently */{ if (Findr (i) ==findr (j)) continue; if (Solve (LINE[I],LINE[J))) Unite (I,J); } while (1) {int A, B; scanf ("%d%d", &a,&b); if (!a| |! b) break; if (Findr (a) ==findr (b)) printf ("connected\n"); else printf ("Not connected\n"); }} return 0;}
Analysis: Cross-Stand experiment template + and check set
POJ 1127 Jack Straws segment intersect + and check set