Test instructions: Can a polygon composed of n vertices form a regular polygon?
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>Ten using namespacestd; One Const intmaxn=111; A Const intMaxnode=4000010; -typedefLong LongLL; - struct Point the { - intx, y; -Point (intx=0,inty=0): X (x), Y (y) {} - + } P[MAXN]; - typedef point Vector; +Vectoroperator+(Vector a,vector B) A { at returnVector (a.x+b.x,a.y+b.y); - } - -Vectoroperator-(Point a,point B) - { - returnVector (a.x-b.x,a.y-b.y); in } -Vectoroperator* (Vector A,intp) to { + returnVector (a.x*p,a.y*p); - } the *Vectoroperator/(Vector A,intp) $ {Panax Notoginseng returnVector (a.x/p,a.y/p); - } the + BOOL operator< (ConstPoint&a,ConstPoint &b) A { the returna.x<b.x| | (a.x==b.x&&a.y<b.y); + } - $ intCross (Vector a,vector B) $ { - returna.x*b.y-a.y*b.x; - } the - intConvexhull (Point *p,intN,point *ch)Wuyi { theSort (p,p+n); - intm=0; Wu for(intI=0; i<n; i++) - { About while(m>1&&cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) $m--; -ch[m++]=P[i]; - } - intk=m; A for(inti=n-2; i>=0; i--) + { the while(M>k&&cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--; -ch[m++]=P[i]; $ } the if(n>1) them--; the returnm; the } - intN; in Point ANS[MAXN]; the ll Dis (ll x1,ll y1,ll x2,ll Y2) the { About return(x1-x2) * (X1-X2) + (y1-y2) * (y1-Y2); the } the intMain () the { +Freopen ("In.txt","R", stdin); - intT; thescanf"%d",&t);Bayi while(t--) the { thescanf"%d",&n); - for(intI=0; i<n; i++) -scanf"%d%d",&p[i].x,&p[i].y); the intm=Convexhull (P,n,ans); the if(m!=N) the { theprintf"no\n"); - Continue; the } the BOOLflag=true; theLL Len=dis (ans[0].x,ans[0].y,ans[m-1].x,ans[m-1].y);94 the for(intI=1; i<m; i++) the { the if(Len!=dis (ans[i].x,ans[i].y,ans[i-1].x,ans[i-1].y))98 { Aboutflag=false; - Break;101 }102 }103 if(flag) printf ("yes\n");104 Elseprintf"no\n"); the 106 }107 return 0;108}View Code
2015 Changchun HDU 5531 Rebuild