标签:blog io os ar 2014 sp 代码 log on
给出两点,求经过这两点的正n边形的最小面积
大白鼠上说要注意精度,我没觉得精度有什么影响,然后就过了
我的做法:
相当于这两点构成的线段是正n边形的最长弦
我的代码:
#include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; const double pi=acos(-1.0); struct dot { int x,y; dot(){} dot(double a,double b){x=a;y=b;} }; int main() { int n; double c,d,s; dot a,b; while(cin>>a.x>>a.y>>b.x>>b.y>>n) { if(a.x+a.y+b.x+b.y+n==0) break; c=2*pi/n; d=pow(a.x-b.x,2)+pow(a.y-b.y,2); if(n&1) s=d*n*sin(c)/4/(1-cos(pi*(n-1)/n)); else s=d*sin(c)*n/8; printf("%.6lf\n",s); } }
UVA12300-Smallest Regular Polygon
标签:blog io os ar 2014 sp 代码 log on
原文地址:http://blog.csdn.net/stl112514/article/details/39212013