PAT T1011 Cut Rectangles
大模拟题,按要求建立多边形,先定位斜边的位置,再分类讨论~
#include<bits/stdc++.h> using namespace std; const int maxn=1014; struct node { double x,y; }Node[2][maxn]; double distance (node a,node b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } int isXiebian (node a,node b) { if (a.x!=b.x&&a.y!=b.y) return 1; return 0; } double angle (node a,node b) { return fabs(a.x-b.x)/fabs(a.y-b.y); } vector<double> edge[2]; int main () { int T; scanf ("%d",&T); int k1,k2; while (T--) { edge[0].clear();edge[1].clear(); scanf ("%d",&k1); for (int i=0;i<k1;i++) scanf ("%lf %lf",&Node[0][i].x,&Node[0][i].y); scanf ("%d",&k2); for (int i=0;i<k2;i++) scanf ("%lf %lf",&Node[1][i].x,&Node[1][i].y); double xie1=0,xie2=0,cnt1=0,cnt2=0,angle1,angle2,p1,p2; for (int i=0;i<k1;i++) { int j=i<k1-1?i+1:0; if (isXiebian(Node[0][i],Node[0][j])) xie1=distance(Node[0][i],Node[0][j]),cnt1++, angle1=angle(Node[0][i],Node[0][j]); edge[0].push_back(distance(Node[0][i],Node[0][j])); } for (int i=0;i<k2;i++) { int j=i<k2-1?i+1:0; if (isXiebian(Node[1][i],Node[1][j])) xie2=distance(Node[1][i],Node[1][j]),cnt2++, angle2=angle(Node[1][i],Node[1][j]); edge[1].push_back(distance(Node[1][i],Node[1][j])); } if (k1+k2>8||k1+k2<6) printf ("NO\n"); else if (xie1==xie2&&cnt1==1&&cnt2==1) { if ((angle1==angle2||angle1*angle2==1)&&(k1!=4||k2!=4)) printf ("YES\n"); else if (k1==4&&k2==4) { double z1=p1<k1-2?p1+2:p1+2-k1; double z2=p2<k2-2?p2+2:p2+2-k2; double z3=p1<k1-1?p1+1:0; double z4=p1>0?p1-1:k1-1; double z5=p2<k2-1?p2+1:0; double z6=p2>0?p2-1:k2-1; if (edge[0][z1]==edge[0][z2]&&(edge[0][z3]+edge[1][z5]==edge[0][z4]+edge[1][z6]|| edge[0][z3]+edge[1][z6]==edge[0][z4]+edge[1][z5])) printf ("YES\n"); else printf ("NO\n"); } else printf ("NO\n"); } else if (xie1==0&&xie2==0&&k1==4&&k2==4) { for (int i=0;i<k1;i++) { for (int k=0;k<k2;k++) if (edge[0][i]==edge[1][k]) cnt1++; } if (cnt1==8||cnt1==16) printf ("YES\n"); else printf ("NO\n"); } else printf ("NO\n"); } return 0; }