pro:给定规则的多边形,规则是指顶点都在整点上,而且是相互垂直的边的交点。 现在给定两个多边形A,B,问A,B缩小,旋转后是否可以变为同一个图形。
sol:缩小的话,直接离散化即可,就可以去掉没用的部分,旋转的话,可以手动旋转4次。
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int maxn=610; struct in{ int N,a[maxn],b[maxn],x[maxn],y[maxn]; int lx,ly; void init() { scanf("%d",&N); rep(i,1,N) scanf("%d%d",&a[i],&b[i]); rep(i,1,N) x[i]=a[i],y[i]=b[i]; sort(x+1,x+N+1); sort(y+1,y+N+1); lx=unique(x+1,x+N+1)-(x+1); rep(i,1,N) a[i]=lower_bound(x+1,x+lx+1,a[i])-x; ly=unique(y+1,y+N+1)-(y+1); rep(i,1,N) b[i]=lower_bound(y+1,y+ly+1,b[i])-y; } void turn() { rep(i,1,N){ int t=a[i],q=b[i]; a[i]=q; b[i]=-t+lx+1; } swap(lx,ly); } }A,B; bool equel() { int pos=0; rep(i,1,A.N){ if(A.a[i]==B.a[1]&&A.b[i]==B.b[1]){ pos=i; break; } } if(!pos) return false; rep(i,pos,A.N) if(A.a[i]!=B.a[i+1-pos]||A.b[i]!=B.b[i+1-pos]) return false; rep(i,1,pos-1) if(A.a[i]!=B.a[A.N-pos+i+1]||A.b[i]!=B.b[A.N-pos+i+1]) return false; return true; } int main() { A.init(); B.init(); if(A.N!=B.N) return puts("no"),0; rep(i,1,5){ if(equel()) return puts("yes"),0; A.turn(); } puts("no"); return 0; }