C. Ancient Berland Circus
time limit per test2 seconds
memory limit per test64 megabytes
inputstandard input
outputstandard 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.
Examples
input
0.000000 0.000000
1.000000 1.000000
0.000000 1.000000
output
1.00000000
题目大意就是 一个马戏团是一个正多边形的形状,现在只给出其中三个角的坐标,求出这个正多边形的最小面积。
直接上数学推导公式,要想保证多边形面积最小,就要保证多边形任意三点组成三角形的外接圆都是同一个。所有要求出多边形的面积S,就要求出多个小三角形的面积求和就是多边形的面积。
通过gcd找到给出三个点于外接圆半径r组成角的最大公约数即为多边形各个小三角形的内角∠α,在通过初高中学的三角函数就可以求出面积啦。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<stack>
#include<iostream>
#include<algorithm>
const int maxn=1e5+10;
const int INF=0x3f3f3f3f;
const double Pi = 3.1415926535;
using namespace std;
#define epi 1e-3
double gcd(double x,double y){
if(fabs(x)<epi)
return y;
if(fabs(y)<epi)
return x;
return gcd(y,fmod(x,y));
}
int main(){
double x1,x2,x3,y1,y2,y3;
double a,b,c;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
a = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
c = sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
double p = (a+b+c)/2;
double s = sqrt(p*(p-a)*(p-b)*(p-c));
double r = a*b*c/(4*s);
double angle1 = acos(1-(a*a/(2*r*r)));
double angle2 = acos(1-(b*b/(2*r*r)));
double angle3 = 2*Pi - angle1 - angle2;
double angle = gcd(angle1,gcd(angle2,angle3));
double S = 0.5*r*r*sin(angle)*(2*Pi/angle);
printf("%.6lf",S);
}