Codeforces Beta Round #1 C. Ancient Berland Circus
来源:互联网 发布:淘宝关键词怎么写 编辑:程序博客网 时间:2024/05/16 16:03
原题链接:
http://codeforces.com/contest/1/problem/C
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.
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 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.
0.000000 0.0000001.000000 1.0000000.000000 1.000000
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;}
- Codeforces Beta Round #1 C. Ancient Berland Circus
- Codeforces Beta Round #1 C. Ancient Berland Circus
- Codeforces Beta Round #1 C Ancient Berland Circus
- Codeforces Beta Round #1 C. Ancient Berland Circus
- Codeforces Beta Round #1 C. Ancient Berland Circus
- Codeforces Beta Round #1 C. Ancient Berland Circus
- Codeforces Round #1C Ancient Berland Circus
- Codeforces Beta Round #1 C. Ancient Berland Circus (计算几何)
- Codeforces 1C Ancient Berland Circus
- CodeForces #1 C. Ancient Berland Circus
- codeforces 1C Ancient Berland Circus
- CodeForces-1C-Ancient Berland Circus
- CodeForces 1C Ancient Berland Circus
- CodeForces 1C - Ancient Berland Circus
- Codeforces #1 C. Ancient Berland Circus
- Codeforces 1C Ancient Berland Circus
- codeforces C. Ancient Berland Circus
- 1C. Ancient Berland Circus
- 以后我要好好写博客了
- 10943 - How do you add?(隔板法)
- swift学习记录(开端)
- JAVA菜鸟入门(1) ReadFile
- HTML+CSS交互 (3)
- Codeforces Beta Round #1 C. Ancient Berland Circus
- 构造函数与复制构造函数
- 菏泽曹县成武郓城巨野单县定陶东明网站建设
- UVa 11258 String Partition(DP)
- log4j使用
- BZOJ2761 不重复数字
- 简单方便的大众型视频编辑器“编辑星”正式免费开放
- Android软件开发之获取通讯录联系人信息(二十九)
- Code[VS] 1029 遍历问题