UVA 12300 Smallest Regular Polygon(正多边形)
题意:给出两点,求经过这两点的正n边形的最小面积
题解:这两点一定是最长的弦,我们设正多边形中点c,找到c到每个点的距离(都相同)
我们知道那个等腰三角形的底与每个角度就使用余弦定理
#include<set> #include<map> #include<queue> #include<stack> #include<cmath> #include<vector> #include<string> #include<cstdio> #include<cstring> #include<iomanip> #include<stdlib.h> #include<iostream> #include<algorithm> using namespace std; #define eps 1E-8 /*注意可能会有输出-0.000*/ #define Sgn(x) (x<-eps? -1 :x<eps? 0:1)//x为两个浮点数差的比较,注意返回整型 #define Cvs(x) (x > 0.0 ? x+eps : x-eps)//浮点数转化 #define zero(x) (((x)>0?(x):-(x))<eps)//判断是否等于0 #define mul(a,b) (a<<b) #define dir(a,b) (a>>b) typedef long long ll; typedef unsigned long long ull; const int Inf=1<<28; const ll INF=1ll<<60; const double Pi=acos(-1.0); const int Mod=1e9+7; const int Max=10010; double Dis(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } double Trg(double dis) { double hrep=dis*3.0/2; return sqrt(hrep*dis/2*dis/2*dis/2); } int main() { int x1,y1,x2,y2; int n; while(~scanf("%d %d %d %d %d",&x1,&y1,&x2,&y2,&n)) { if(!x1&&!y1&&!x2&&!y2&&!n) break; double ang,dis; dis=Dis(x1,y1,x2,y2); ang=360.0/n*Pi/180; if(n==3) { printf("%.6f\n",Trg(dis)); } else if(n&1) { dis=sqrt(dis*dis/(2.0*(1-cos(ang*(n/2))))); printf("%.6f\n",0.5*dis*dis*sin(ang)*n); } else { dis/=2; printf("%.6f\n",0.5*dis*dis*sin(ang)*n); } } return 0; }