hdu 4195(几何+思路+好题)
题意,有一个n多边形,且是正多边形,从中任取3点构成一个三角形。告诉你这3个点的坐标,求满足条件的最小的n。
基本思路:在n多边形外画一个圆找规律。暴力,从i(3<=i<=1000)边形开始,判断是否满足条件。判断方法是求三角形的3个角,*2即三角形的三条边对应的圆心角的度数(貌似是高中学过的定理),然后判断这个度数能不能被(π*2/i)整除,判断时要控制精度。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//#pragma comment(linker, "/STACK:102400000") #include<cstdlib> #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<set> #include<map> #include<list> #include<queue> #include<vector> #define tree int o,int l,int r #define lson o<<1,l,mid #define rson o<<1|1,mid+1,r #define lo o<<1 #define ro o<<1|1 #define ULL unsigned long long #define LL long long #define inf 0x7fffffff #define eps 1e-7 #define N 105 const double PI=acos(-1.0); using namespace std; int m,n,T,t,x,y,u; int dcmp(double x) { if(fabs(x)<eps)return 0; return x>0?1:-1; } struct Point { double x,y; int read() { return scanf("%lf%lf",&x,&y); } Point(double xx=0,double yy=0) { x=xx; y=yy; } Point operator-(Point a) { return Point(x-a.x,y-a.y); } } p[3]; double length(Point a) { return sqrt(a.x*a.x+a.y*a.y); } double ang[3]; double get(Point a,Point b,Point c) { double aa=length(b-c); double bb=length(a-c); double cc=length(b-a); double tp=(aa*aa+bb*bb-cc*cc)/(aa*bb*2); return acos(tp)*2.0; } int main() { #ifndef ONLINE_JUDGE freopen("ex.in","r",stdin); #endif while(p[0].read()==2) { p[1].read(); p[2].read(); ang[0]=get(p[0],p[1],p[2]); ang[1]=get(p[1],p[2],p[0]); ang[2]=get(p[2],p[0],p[1]); for(int i=3; i<=1000; i++) { double g=PI*2/i; int ok=1; for(int j=0; j<3; j++) { int num=ang[j]/g+0.5;//四舍五入 if(dcmp(num*g-ang[j])!=0) ok=0; } if(ok) { printf("%d\n",i);break; } } } return 0; }