Codeforces 1C Ancient Berland Circus

Ancient Berland Circus

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

 题目大意

       来自伯兰的科学家们发现了古代马戏团竞技场仅剩的三根柱子,已知竞技场是一个规则的等边多边形,已知三跟柱子的坐标,求竞技场可能拥有的最小面积(误差精确至10^{-6})。每根柱子坐标的绝对值≤1000,多边形边的数目≤100.

题目分析

        通过题目概述我们可以计算出三条边的长度。记读入的三个坐标分别为(x1,y1),(x2,y2),(x3,y3)。那么三条边的长度分别为:

a=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
b=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
c=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));

 不会吧这还有人不知道


 1.首先我们需要分析不同的正多边形画出三角形的所有可能的角度。
        不难发现下面列出的边与角度具有一定的关系。
        
        正三边形:60°
        正四边形:45°,90°
        正五边形:36°,72°,108°
        正六边形:30°,60°,90°,120°
        ... ...

        正i边形能划分的最小角度为\frac{180}{i}度,最大角度为180-\frac{360}{i}度。所有可能角度按从小到大排序,它们以最小角度为公差依次递增,最大角度与最小角度的比值为 k=(i-2).

2.考虑最优情况
        根据余弦定理可以得知三角形的三个角度,若此三角形取自正i边形,则这三个角度必然包含于正i边形所有可能角度的集合中。例如:30°,45°,105°可能取自正12边形,正24边形,正36边形等。
        这么多的情况何种正边形保证面积最小?
        当然是边最少的正边形。因为在这些可能的正边形中,它们具有相同的外接圆半径,而边数越多,越接近于圆形,所占面积越大。
        因此在知道角度的情况下,我们可以从最少边的正变形(正三边形开始)逐一判断。判断条件为:三角形的三个角度是否都能被正i边形的最小角整除。

3.如何计算最终结果
        根据正弦定理首先求出正i边形的边长n:\frac{n}{sin(\frac{180}{i})}=\frac{a}{sin(A)}
        已知正多边形边数i,边长为n,根据正多边形面积公式计算出结果。

AC代码

#include<bits/stdc++.h>
using namespace std;
const double pi=3.14159265358979;
vector<double>v(105);
void init(){
	v[3]=60.0;
	v[4]=45.0;
	for(int i=5;i<=100;i++){
		double r=180.0/i;
		v[i]=r;
	}
}
int main(){
	init();//v[i]表示i边形 能画出三角形的最小角度 
	double x1,x2,x3,y1,y2,y3;
	cin>>x1>>y1>>x2>>y2>>x3>>y3;
	double a,b,c;
	a=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	b=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
	c=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
	double A,B,C;//*180/pi --- 弧度转角度 
	C=acos((a*a+b*b-c*c)/(2*a*b))*180/pi;//A表示边c所对三角形的角度 
	A=acos((b*b+c*c-a*a)/(2*b*c))*180/pi;//B表示边a所对三角形的角度 
	B=acos((c*c+a*a-b*b)/(2*c*a))*180/pi;//C表示边b所对三角形的角度 
	for(int i=3;i<=100;i++){
		if(abs(A/v[i]-double(int(A/v[i]+0.000005)))<=0.000005&&abs(B/v[i]-int(B/v[i]+0.000005))<=0.000005&&abs(C/v[i]-int(C/v[i]+0.000005))<=0.000005){
			//abs(A/v[i]-double(int(A/v[i]+0.000005)))<=0.000005 判断是否能被整除 
			double n;
			n=c*sin(v[i]*pi/180)/sin(C*pi/180);//求多边形边长  根据公式c/sin(C)= n/sin(v[i])
			cout<<fixed<<setprecision(8)<<i*n*n*sin(2*pi/i)/(4*(1-cos(2*pi/i)))<<endl;//已知多边形 为i边形,边长为n,根据面积公式S=[i*n*n*sin(360/i)]/[4*(1-cos(360/n))]
			break;
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值