CodeForces 1C(计算几何)

时间:2023-02-10 20:25:52

问题描述:

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.

Example

Input
0.000000 0.000000
1.000000 1.000000
0.000000 1.000000
Output
1.00000000

题目题意:题目给我们一个正多边形的三个点,让我们求出这个多边形的可能最小面积。

题目分析:我们可以先利用这个三个点来求出外接圆的半径

R=a*b*c/4*s;

然后我们求出这个三角形三个内角,那么它对应的圆心角就是它角度的俩倍,也就是得到了三段弧长对应的角度,我们求这个三个角度的最大公约角D。

2*PI/D就是小三角形的个数,乘以每个三角形的面积就是多边形的面积。

题目题意:

#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;

const double PI=acos(-1.0);
const double eps=1e-2;//精度高了还不行
struct note
{
    double x,y;
}a,b,c;
double get_dis(note a,note b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double fgcd(double a,double b)
{
    if (fabs(b)<eps) return a;
    return fgcd(b,fmod(a,b));
}

int main()
{
    while (scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y)!=EOF) {
        double A,B,C,D,S,R,ac,bc,ab;
        ac=get_dis(a,c);
        ab=get_dis(a,b);
        bc=get_dis(b,c);
        A=acos((ac*ac+ab*ab-bc*bc)/(2*ac*ab));
        B=acos((bc*bc+ab*ab-ac*ac)/(2*bc*ab));
        C=acos((ac*ac+bc*bc-ab*ab)/(2*ac*bc));
        R=bc/(2*sin(A));
        A*=2,B*=2,C*=2;
        D=fgcd(fgcd(A,B),fgcd(A,C));
        printf("%.8f\n",R*R*sin(D)/2.0*((2*PI)/D));
    }
    return 0;
}