HDU 4195 Regular Convex Polygon
思路:三角形的圆心角可以整除(2*pi)/n
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<queue> 5 #include<stack> 6 #include<algorithm> 7 using namespace std; 8 #define clc(a,b) memset(a,b,sizeof(a)) 9 #define inf 0x3f3f3f3f 10 const int N=10010; 11 #define LL long long 12 const double eps = 1e-5; 13 const double pi = acos(-1); 14 // inline int r(){ 15 // int x=0,f=1;char ch=getchar(); 16 // while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();} 17 // while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 18 // return x*f; 19 // } 20 struct Point{ 21 double x,y; 22 Point(double a=0,double b=0):x(a),y(b){} 23 }; 24 25 double angle(Point a,Point b,Point c){ 26 b.x-=a.x,b.y-=a.y; 27 c.x-=a.x,c.y-=a.y; 28 return acos((b.x*c.x+b.y*c.y)/(hypot(b.x,b.y)*hypot(c.x,c.y))); 29 } 30 31 bool dcmp(double f,int n){ 32 return fabs(f * n - round(f * n)) < eps; 33 } 34 35 int main(){ 36 while(1){ 37 Point p[3]; 38 for(int i=0;i<3;i++) 39 if(scanf("%lf%lf",&p[i].x,&p[i].y)!=2) return 0; 40 double a=angle(p[0],p[1],p[2])/pi; 41 double b=angle(p[1],p[2],p[0])/pi; 42 for(int i=3;i<=1000;i++){ 43 if(dcmp(a,i)&&dcmp(b,i)){ 44 printf("%d\n",i); 45 break; 46 } 47 } 48 } 49 return 0; 50 }