题目链接:点击打开链接
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
0.000000 0.000000 1.000000 1.000000 0.000000 1.000000
1.00000000
题目大意:给出三个点的坐标 ,这三个点一定能组成三角形,问经过这三个点所能组成的最小面积的正多边形。
基本思路:几何,
1》根据i这三个点画出三角形来,先求出三条边a,b,c,
2》通过海伦公式求出三角形的面积s
3》画出这个三角形的外接圆(这三个点在此外接圆上,如果是正多边形,则正多边形的点都应该在这个外接圆上)
求外接圆的半径r=abc/4s;(有兴趣的话具体证明去百度)
4》在求出每条边对应的圆心角(共三个):代码注释有讲解
5》求出三个圆心角的最大公约数(因为这三个角度的最大公约数就是多边形每条边对应的角度,且是最小面积的多边形,需要脑补一下,)area;
6>2PI/area是多边形的边数n
7》计算以area为角度的三角形的面积是多边形的最小单元面积,由公式ss=a*b*sin(@)/2的到
最后n*ss即为所求面积
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const double PI=3.1415926535;
const double esp=0.01;
double x[3],y[3];
double eage(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double gcd(double a,double b)
{
///求最大公约数时,因为是小数,所以根据精度返回
if(a<esp)return b;
if(b<esp)return a;
return gcd(b,fmod(a,b));///fmod是对浮点数取余 的函数,在cmath中
}
int main()
{
for(int i=0;i<3;i++)
{
scanf("%lf%lf",&x[i],&y[i]);
}
double a,b,c;
///求出三边
a=eage(x[0],y[0],x[1],y[1]);
b=eage(x[0],y[0],x[2],y[2]);
c=eage(x[2],y[2],x[1],y[1]);
///海伦公式
double p,s,r;
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-b)*(p-c));
///求外接圆的半径
r=(a*b*c)/(4*s);
double angle[3];
///求每条边对应的角度,根据从圆心到顶点的构成的三角形是等腰的求
angle[0]=2*asin(a/(2*r));
angle[1]=2*asin(b/(2*r));
angle[2]=2*PI-angle[0]-angle[1];
double aver=angle[0];
for(int i=1;i<3;i++)
{
aver=gcd(aver,angle[i]);
}
///几边形
double n=2*PI/aver;
///每一个小三角形的面积(角度为area)
double area=r*r*sin(aver)/2;
printf("%.6lf\n",n*area);
return 0;
}