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
题目大意
对于一个正多边形,只给出了其中三点的坐标,求这个多边形可能的最小面积,给出的三个点一定能够组成三角形。
思路
对于给定的三角形,其外接圆半径大小是一定的;在外接圆半径大小一定的情况下,要使正多边形面积最小,就是使正多边形的边数最少,也就是使得每条边所对应的圆心角最大。
而最大圆心角 = 三角形三条边所对应的三个圆心角的公约数,在下图中,也就是∠1、∠2和∠3的最大公约数。
步骤
代码
#include <stdio.h> #include <string.h> #include <string> #include <iostream> #include <algorithm> #include <vector> #include <math.h> #include <map> #include <queue> #include <stack> #include <set> #define maxn 100005 #define LL long long #define ll __int64 #define eps 1e-4 #define INF 1e8 #define pi acos(-1.0) #define mol 200907 using namespace std; struct Point { double x,y; }; double dist(Point p1,Point p2) { return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); } double Angle(double a,double b,double c) { return acos((a*a+b*b-c*c)/(2*b*a)); } double gcd(double a,double b) { if(b+eps>0&&b-eps<0) return a; if(a+eps>0&&a-eps<0) return b; return gcd(b,fmod(a,b)); } int main() { Point p1,p2,p3; while(~scanf("%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y)) { double a,b,c,p,s,r; double angle1,angle2,angle3,angle; a=dist(p1,p2); b=dist(p1,p3); c=dist(p2,p3); p=(a+b+c)/2; s=sqrt(p*(p-a)*(p-b)*(p-c)); r=a*b*c/(4*s); angle1=Angle(r,r,a); angle2=Angle(r,r,b); angle3=2*pi-angle1-angle2; angle=gcd(angle1,gcd(angle2,angle3)); double ans; ans=0.5*r*r*sin(angle)*(2*pi/angle); printf("%.6lf\n",ans); } return 0; }