Codeforces Beta Round #1 C. Ancient Berland Circus

来源:互联网 发布:淘宝关键词怎么写 编辑:程序博客网 时间:2024/05/16 16:03

原题链接:

http://codeforces.com/contest/1/problem/C

C. Ancient Berland Circus
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.

In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges.

Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time.

You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have.

Input

The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.

Output

Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.

Sample test(s)
input
0.000000 0.0000001.000000 1.0000000.000000 1.000000
output
1.00000000


题意:给你多边形的三个顶点坐标,要求你计算出满足条件的最小的多边形面积。

思路:

①求出多边形的中心,也就是一直三个点的三角形的外心,这里百度到了一个很高端很实用的求外心公式。

②求出外心和三个顶点形成的三个角。

③我们可以知道在半径确定的情况下,边数越大面积越大,所以我们希望边数尽量小。从3到100枚举β角,如果满足已知的三个角都能被β角整除

多边形的β角:



外心公式:

△ABC,边a,b,c
P=1/2*(a^2+b^2+c^2);
Q=1/((1/(P-a^2)+1/(P-b^2)+1/(P-c^2))
λ1=Q/(P-a^2),λ2=Q/(P-b^2),λ3=Q/(P-c^2);(注:λ1+λ2+λ3=1)  
垂心:H(x,y)=λ1*A(x,y)+λ2*B(x,y)+λ3*C(x,y),  
重心:G(x,y)=1/3*A(x,y)+1/3*B(x,y)+1/3*C(x,y),  
外心:O(x,y)=(1-λ1)/2*A(x,y)+(1-λ2)/2*B(x,y)+(1-λ3)/2*C(x,y);  
S△=1/2*a*b*sin(C);


注意:这道题的精度只能开到0.00001,可能是计算太多误差比较大吧。


代码:

#include "stdio.h"#include "iostream"#include "string.h"#include "stdlib.h"#include "algorithm"#include "math.h"using namespace std;const double pai=3.141592653589;const double eps=0.00001;struct point{double x;double y;}p[3],w;double a,b,c,ang[110],nang[3];void getang(){for(int i=3;i<=100;i++){ang[i]=2*pai/i;}}double dis(struct point p1,struct point p2){double res;res=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));return res;}double getnang(struct point p1,struct point p2,struct point p3){double res;double x1=p1.x-p3.x,y1=p1.y-p3.y;double x2=p2.x-p3.x,y2=p2.y-p3.y;double co=(x1*x2+y1*y2)/(sqrt(x1*x1+y1*y1)*sqrt(x2*x2+y2*y2));return acos(co);}int main(){getang();for(int i=0;i<3;i++)scanf("%lf%lf",&p[i].x,&p[i].y);a=dis(p[0],p[1]);b=dis(p[0],p[2]);c=dis(p[1],p[2]);double P=0.5*(a*a+b*b+c*c);double Q=1.0/(1.0/(P-a*a)+1.0/(P-b*b)+1.0/(P-c*c));double q1=Q/(P-a*a),q2=Q/(P-b*b),q3=Q/(P-c*c);w.x=(1-q1)/2*p[2].x+(1-q2)/2*p[1].x+(1-q3)/2*p[0].x;w.y=(1-q1)/2*p[2].y+(1-q2)/2*p[1].y+(1-q3)/2*p[0].y;nang[0]=getnang(p[0],p[1],w);nang[1]=getnang(p[0],p[2],w);nang[2]=getnang(p[1],p[2],w);int flag=1;for(int i=3;i<=100;i++){double x;for(int j=0;j<3;j++){flag=0;x=nang[j]/ang[i];if(x-floor(x)<=eps||ceil(x)-x<=eps){flag=i;}if(flag==0)break;}if(flag)break;}double R=dis(p[0],w);double s=0.5*R*R*sin(ang[flag]);printf("%.8lf\n",s*flag);return 0;}


0 0
原创粉丝点击