D - Ancient Berland Circus

来源:互联网 发布:淘宝拒签快递怎么退款 编辑:程序博客网 时间:2024/06/01 16:48

D - Ancient Berland Circus
Crawling in process...Crawling failed
Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

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

Input
0.000000 0.0000001.000000 1.0000000.000000 1.000000
Output
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,得一个三角形的面积,则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;}




0 0
原创粉丝点击