CF 1C.Ancient Berland Circus

有点慢的CF

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.
Examples

Input

0.000000 0.000000
1.000000 1.000000
0.000000 1.000000

Output

1.00000000

题意

给出一个正多边形的其中三个点坐标,然后求这个正多边形的最小面积.

思路

某人一看这题:“显然,把这三个点连起来,这就是个三角形”
废话不多说,直接上图从洛谷拿的图,嘿嘿~emmm,首先这三个点都位于一个多边形上.那么,站在这个正多边形的角度上,这三个点到这个正多边形的中心的距离一定是相等的,对不对?那站在三角形的角度上,到三角形三个点的距离都相等的点只有这个三角形外接圆的圆心,如图所示,三角形外接圆圆心与正多边形中心重合.

那么该怎么求这个正多边形的面积呢?

接下来就要用上我这个蒟蒻看得半懂不懂的Math部分了.

已知的是三角形三点坐标,借此可以求出三角形三边长 a , b , c a, b, c a,b,c,结合海伦公式 S Δ A B C = p ( p − a ) ( p − b ) ( p − c ) ( p = a + b + c 2 ) S_{\Delta ABC}=\sqrt{p(p-a)(p-b)(p-c)}(p=\frac{a+b+c}{2}) SΔABC=p(pa)(pb)(pc) (p=2a+b+c)可以求得三角形面积。

可以证明 S Δ A B C = a h a 2 = a b sin ⁡ C 2 S_{\Delta ABC}=\frac{ah_{a}}{2}=\frac{ab\sin C}{2} SΔABC=2aha=2absinC​,结合正弦定理 a sin ⁡ A = b sin ⁡ B = c sin ⁡ C = 2 R \frac{a}{\sin A}=\frac{b}{\sin B}=\frac{c}{\sin C}=2R sinAa=sinBb=sinCc=2R即可得出三角形外接圆半径 R = a b c 4 S Δ A B C ​ ​ R=\frac {abc}{4S_{\Delta ABC}​}​ R=4SΔABCabc

根据余弦定理分别求出三角形三边作为弦所对的圆心角的三角函数值,使用反三角函数求出圆心角的度数,由于圆心角的度数皆为正多边形中心角度数的倍数,可以通过求圆心角度数的最大公约数求出正多边形的中心角度数t,已知组成正多边形的三角形面积为 S Δ = R 2 sin ⁡ t 2 S_{\Delta}=\frac {R^2{\sin t}}{2} SΔ=2R2sint​,而这样的三角形有 2 π t \frac{2 \pi}{t} t2π个,于是正多边形面积为 π R 2 sin ⁡ t t \frac{\pi R^2\sin t}{t} tπR2sint.
math部分转自Loner_Knowledge

代码
#include <cmath>
#include <cstdio>
#define R register int 
using namespace std;
const double pi=acos(-1.0);
const double EPS=1e-2;
double x[4], y[4];

double gcd(double a, double b){
	if(fabs(b)<EPS)	return a;
	if(fabs(a)<EPS) return b;
	return gcd(b, fmod(a, b));
}

int main (){
	double a, b, c, p, S, A, B, C, T, D, r;
	
	for (R i=1;i<=3;++i) scanf ("%lf%lf", &x[i], &y[i]);	
	a=sqrt((x[1]-x[2])*(x[1]-x[2])+(y[1]-y[2])*(y[1]-y[2]));
	b=sqrt((x[3]-x[1])*(x[3]-x[1])+(y[3]-y[1])*(y[3]-y[1]));
	c=sqrt((x[2]-x[3])*(x[2]-x[3])+(y[2]-y[3])*(y[2]-y[3]));
	p=(a+b+c)/2;
	S=sqrt(p*(p-a)*(p-b)*(p-c));
	r=(a*b*c)/(4*S);
	A=acos(1-(a*a)/(2*r*r));
	B=acos(1-(b*b)/(2*r*r));
	C=2*pi-A-B;
	T=gcd(A, gcd(B, C));
	printf("%.6lf\n", (pi*r*r*sin(T))/T);
	
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值