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.
Examples
Input
0.000000 0.000000
1.000000 1.000000
0.000000 1.000000
Output
1.00000000
思路:
- 各点肯定都在外接圆上,边越多越接近圆面积,所以要最小面积应当取可能的最少边数;
- 给三角形求外接圆半径公式:R=abc/4SR;
- 三个角度对应的圆心角取gcd即是要求的正多边形的一个角度,然后求面积即可。注意三个圆心角的求法是三个内角乘2;
- 注意:下面代码中我补充了输入输出,以及第一个案例的输出结果是1.0...04,但是答案一样是对的。
-
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<cmath> using namespace std; #define PI acos(-1.0) //3.1415926 //PI=acos(-1)有时候可能存在问题 double pf(double x){ return x*x; } double gcd(double a,double b){ if (a<1e-3) return b; if (b<1e-3) return a; return gcd(b,fmod(a,b)); } int main(){ double x1,x2,x3,y1,y2,y3; //输入 cin>>x1>>y1; cin>>x2>>y2; cin>>x3>>y3; double a=sqrt(pf(x1-x2)+pf(y1-y2)); double b=sqrt(pf(x2-x3)+pf(y2-y3)); double c=sqrt(pf(x1-x3)+pf(y1-y3)); //海伦公式 double C=(a+b+c)/2; double r=a*b*c/4/sqrt(C*(C-a)*(C-b)*(C-c)); //计算角度 double aerf=acos((2*pf(r)-pf(a))/2/r/r); double bta=acos((2*pf(r)-pf(b))/2/r/r); double gma=2*PI-aerf-bta; //计算最大公因数 double sta=gcd(gcd(aerf,bta),gma); //输出结果 printf("%.8lf\n",sin(sta)*(PI/sta)*pf(r)); } /*input 0.000000 0.000000 1.000000 1.000000 0.000000 1.000000 output 1.00000000 需要注意的是 Input 71.756151 7.532275 -48.634784 100.159986 91.778633 158.107739 Output 9991.278665811225 Input 18.716839 40.852752 66.147248 -4.083161 111.083161 43.347248 Output 4268.87997505 Input 88.653021 18.024220 51.942488 -2.527850 76.164701 24.553012 Output 1452.52866331 */