本文共 1432 字,大约阅读时间需要 4 分钟。
题意:n个顶点组成的多边形能否形成正多边形?
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 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 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
转载于:https://www.cnblogs.com/ITUPC/p/4964497.html