1. 程式人生 > 其它 >cf------(round)#1 C. Ancient Berland Circus(幾何)

cf------(round)#1 C. Ancient Berland Circus(幾何)

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.000000
1.000000 1.000000
0.000000 1.000000

Output

1.00000000

這道題的題意是: 以一個場地遺蹟,呈現多邊形,但是不知道具體是幾邊形,只知道他的三個點,求能包含這三個點的最小多邊形的面積:
 對於這樣的題目: 思路為:
  先求出他的外接圓,得到外接圓的半徑rr.
  (1外接圓的求法: 
{
    (1) 有給定的座標我們不難求出三條邊的邊長,rea,reb,rec;
    (2) 又海倫公式得到三角形的面積: 周長cc=(rea+reb+rec)/2.0 面積等於: ss=sqrt(cc*(cc-rea)*(cc-reb)*(cc-rec));
    (3) rr=rea*reb*rec/(4*ss);  //證明就不詳細說了
}
得到外接園的半徑之後:
   我們再來求出每一條邊對應的圓心角a,b,c;
   求出a,b,c圓心角的最大公約數st;
這樣我們就可以知道他是邊數: 2*pi/st;
所以得到最小單位的三角形的面積為Area=rr*rr*sin(st)/2;
總面積只需再剩上他的邊數就可以得到.....
程式碼如下:
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 using namespace std;
 5 const double PI = 3.1415926535;
 6 const double esp=0.01;
 7 struct node{
 8   double x,y;
 9   //求兩點之間的長度
10   double solen(node a){
11       return sqrt((a.x-x)*(a.x-x)+(a.y-y)*(a.y-y));
12   }
13 };
14 double dgcd(double a,double b)  //最小公倍數
15 {
16     if(a<esp) return b;
17     if(b<esp) return a;
18     return dgcd(b,fmod(a,b));
19 }
20 int main()
21 {
22   node a,b,c;
23   double rea,reb,rec,Area;
24   double angle[3];  //角度
25   //freopen("test.in","r",stdin);
26   scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
27         rea=a.solen(b);
28         reb=a.solen(c);
29         rec=b.solen(c);
30    //又海倫公式
31    double cc=(rea+reb+rec)/2.0;
32    Area=sqrt(cc*(cc-rea)*(cc-reb)*(cc-rec));
33   //求得外接圓半徑r
34    double  rr=rea*reb*rec/(4*Area);
35    angle[0]=acos(1-rea*rea/(2*rr*rr));
36    angle[1]=acos(1-reb*reb/(2*rr*rr));
37    angle[2]=2*PI-angle[0]-angle[1];
38    //求出角之間的最大公約數
39    double ff=angle[0];
40    for(int i=1;i<3;i++)
41      ff=dgcd(ff,angle[i]);
42   //求得是多少邊行
43    printf("%.6lfn",(rr*rr*PI*sin(ff))/ff);
44   return 0;
45 }