D - Ancient Berland Circus
来源:互联网 发布:淘宝拒签快递怎么退款 编辑:程序博客网 时间:2024/06/01 16:48
Description
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 Input
0.000000 0.0000001.000000 1.0000000.000000 1.000000
1.00000000
给出一个正多边行上三个顶点的坐标,求这个正多边形的面积。
解题思路:
直接求正多边形的面积不好求,但是可以利用正多边形的外接圆,进而间接求出正多边形的面积。
利用海伦公式(p=(a+b+c)/2 S=√p(p-a)(p-b)(p-c))和外接圆半径与三角形面积的关系(r=abc/4S)求出
外接圆半径,利用余弦定理求出以已知三点为顶点的三个圆心角A[0],A[1],A[2](注意:有可能三个已知点在同一段半圆弧上,则此时第三个的圆心角应该用2π-A[0]-A[1], 所以为了避免讨论A[2]=2π-ang[0]-ang[1]),利用fgcd函数求出这三个角的最大公约数A,则正多边形的边数为,利用三角形面积公式S=1/2·r * r * sinA,得一个三角形的面积,则2πS/A即为所求结果。
代码如下:
#include <iostream>#include <cstdio>#include <cmath>#define PI acos(-1)#define eps 0.01using namespace std;double fgcd(double a,double b){ if(b>-eps&&b<eps) return a; else return fgcd(b,fmod(a,b));}double dist(double x0, double x1, double y0, double y1){ return sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));}int main(){ int i; double p,s,r,ang=0,x[3],y[3],l[3],A[3]; for(i=0;i<3;i++) scanf("%lf%lf",&x[i],&y[i]); for(i=0;i<3;i++) l[i]=dist(x[i],x[(i+1)%3],y[i],y[(i+1)%3]); p=(l[0]+l[1]+l[2])/2; s=sqrt(p*(p-l[0])*(p-l[1])*(p-l[2])); r=l[0]*l[1]*l[2]/(s*4); for(i=0;i<3;i++) A[i]=acos(1-l[i]*l[i]/(2*r*r)); A[2]=2*PI-A[0]-A[1]; for(i=0;i<3;i++) ang=fgcd(ang,A[i]); printf("%.6lf\n",r*r*sin(ang)*PI/ang); return 0;}
- D - Ancient Berland Circus
- CF1C Ancient Berland Circus
- Ancient Berland Circus
- CF1C Ancient Berland Circus
- codeforces C. Ancient Berland Circus
- 1C. Ancient Berland Circus
- 1C. Ancient Berland Circus
- 1C. Ancient Berland Circus
- 1C. 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 Round #1C Ancient Berland Circus
- CodeForces 1C Ancient Berland Circus
- codeforces——C. Ancient Berland Circus
- CodeForces 1C - Ancient Berland Circus
- Codeforces #1 C. Ancient Berland Circus
- C++编程思想第二章课后练习
- POJ 1380 Equipment Box(判断一个长方形能不能包含另一个长方形)
- Pascal's Triangle II
- 【C#网络编程系列】专题七:UDP编程补充——UDP广播程序的实现
- 感悟
- D - Ancient Berland Circus
- 第11周项目1-输出星号图
- Sql随机生成一个汉语名字
- 【最短路径】dijkstra算法 pascal
- 模拟赛 密室逃脱(时间限制:1s;空间限制:256MB)
- Plus One
- Codeforces 21C Stripe 2 卧槽,出题人母语绝对不是English啊
- 使用纯C在自己的窗口中嵌入HTML控件
- 关于gbk和utf8下的汉字表示