Codeforces 1C Ancient Berland Circus 计算几何

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
#define PI acos(-1.0)
#define feq(a,b) (fabs(a-b)<1E-4)

double gcd(double a,double b)
{
	if(feq(a,0)) return b;
	if(feq(b,0)) return a;
	return gcd(b,fmod(a,b));
}

inline double bcos( double a, double b, double c )
{
	return acos((b*b+c*c-a*a)/(2.0*b*c));
}

inline double len(double x1,double y1,double x2,double y2)
{
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main()
{
	double x1,y1,x2,y2,x3,y3;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
	double a=len(x1,y1,x2,y2);
	double b=len(x1,y1,x3,y3);
	double c=len(x2,y2,x3,y3);
	double p=0.5*(a+b+c);
	double s_triangle=sqrt(p*(p-a)*(p-b)*(p-c));
	double r=(a*b*c)/(4.0*s_triangle);
	double A=bcos(a,r,r);
	double B=bcos(b,r,r);
	double C=2*PI-A-B;
	double T=gcd(A,gcd(B,C));
	double s;
	s=0.5*r*r*sin(T)*(2*PI/T); //这里wa了好几次,因为把2*PI/T用double类型保存了再算的,倒置关键精度丢失
	cout.setf(ios::fixed);
	cout << setprecision(8) << s << endl;
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值