2015长春 HDU 5531 Rebuild
题意:n个顶点组成的多边形能否形成正多边形?
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <cstdlib> 5 #include <iostream> 6 #include <algorithm> 7 #include <queue> 8 #include <map> 9 #include <vector> 10 using namespace std; 11 const int maxn=111; 12 const int maxnode=4000010; 13 typedef long long LL; 14 struct Point 15 { 16 int x,y; 17 Point (int x=0,int y=0):x(x),y(y) {} 18 19 } p[maxn]; 20 typedef Point Vector; 21 Vector operator+(Vector A,Vector B) 22 { 23 return Vector(A.x+B.x,A.y+B.y); 24 } 25 26 Vector operator-(Point A,Point B) 27 { 28 return Vector(A.x-B.x,A.y-B.y); 29 } 30 Vector operator*(Vector A,int p) 31 { 32 return Vector(A.x*p,A.y*p); 33 } 34 35 Vector operator /(Vector A,int p) 36 { 37 return Vector(A.x/p,A.y/p); 38 } 39 40 bool operator <(const Point&a,const Point &b) 41 { 42 return a.x<b.x||(a.x==b.x&&a.y<b.y); 43 } 44 45 int Cross(Vector A,Vector B) 46 { 47 return A.x*B.y-A.y*B.x; 48 } 49 50 int ConvexHull(Point *p,int n,Point *ch) 51 { 52 sort(p,p+n); 53 int m=0; 54 for(int i=0; i<n; i++) 55 { 56 while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) 57 m--; 58 ch[m++]=p[i]; 59 } 60 int k=m; 61 for(int i=n-2; i>=0; i--) 62 { 63 while(m>k&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--; 64 ch[m++]=p[i]; 65 } 66 if(n>1) 67 m--; 68 return m; 69 } 70 int n; 71 Point ans[maxn]; 72 LL dis(LL X1,LL Y1,LL X2,LL Y2) 73 { 74 return (X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2); 75 } 76 int main() 77 { 78 freopen("in.txt","r",stdin); 79 int t ; 80 scanf("%d",&t); 81 while(t--) 82 { 83 scanf("%d",&n); 84 for(int i=0; i<n; i++) 85 scanf("%d%d",&p[i].x,&p[i].y); 86 int m=ConvexHull(p,n,ans); 87 if(m!=n) 88 { 89 printf("NO\n"); 90 continue; 91 } 92 bool flag=true; 93 LL len=dis(ans[0].x,ans[0].y,ans[m-1].x,ans[m-1].y); 94 95 for(int i=1; i<m; i++) 96 { 97 if(len!=dis(ans[i].x,ans[i].y,ans[i-1].x,ans[i-1].y)) 98 { 99 flag=false; 100 break; 101 } 102 } 103 if(flag)printf("YES\n"); 104 else printf("NO\n"); 105 106 } 107 return 0; 108 }