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 <bits/stdc++.h> using namespace std;
typedef long long ll; typedef pair<int,int> PII; PII a[6],b[6];
inline void input(PII a[],int &n) { scanf("%d",&n); for (int i=0;i<n;i++) { int x,y; scanf("%d%d",&x,&y); a[i]=PII(x,y); } }
inline void check(PII a[],int n,int &X,int &x,int &Y,int &y,int &strt) { X=x=Y=y=strt=0; for (int i=0;i<n;i++) { if (a[i].first==a[(i+1)%n].first) { strt++; int tmp=abs(a[i].second-a[(i+1)%n].second); if (tmp>Y) y=Y,Y=tmp; else y=tmp; } else if (a[i].second==a[(i+1)%n].second) { strt++; int tmp=abs(a[i].first-a[(i+1)%n].first); if (tmp>X) x=X,X=tmp; else x=tmp; } } }
inline bool penta(int n,int m) { int x,X,y,Y,strt; check(b,m,X,x,Y,y,strt); if (strt!=m-1) return false; int A=Y-y,B=X-x; check(a,n,X,x,Y,y,strt); if (strt!=n-1) return false; return (X==A&&Y==B)||(X==B&&Y==A); }
bool quaqua() { int x,X,y,Y,strt; check(b,4,X,x,Y,y,strt); if (strt<3) return false; if (strt==4) { int A=X,B=Y; check(a,4,X,x,Y,y,strt); if (strt!=4) return false; return A==X||A==Y||B==X||B==Y; } int height,A,B; if (y==0) { height=Y;A=X;B=x; } else { height=X;A=Y;B=y; } check(a,4,X,x,Y,y,strt); if (strt<3) return false; if (y==0) { return height==Y&&x+A==X+B; } else { return height==X&&y+A==Y+B; } }
int main() { int T,n,m; scanf("%d",&T); while (T--) { input(a,n); input(b,m); if (n>m) { swap(n,m); swap(a,b); } bool f=false; if (n==4&&m==4) f=quaqua(); else f=penta(n,m); puts(f?"YES":"NO"); } return 0; }
|