CF1C Ancient Berland Circus

对于这种水题,我只想说:

为啥精度只有开1e-3才能过= =


(计算几何水题,大家就不要看了= =)

#include <cstdio>  
#include <cstring>  
#include <cctype>
#include <cstdlib>  
#include <ctime>  
#include <climits>  
#include <cmath>  
#include <iostream>  
#include <string>  
#include <vector>  
#include <set>  
#include <map>  
#include <list>  
#include <queue>  
#include <stack>  
#include <deque>  
#include <algorithm>  
using namespace std;
typedef long long ll;

const double eps = 1e-3;
const double PI = acos(-1.0);

struct Point
{
	double x, y;
	Point(double x=0, double y=0): x(x), y(y) {}
};
typedef Point Vector;

int dcmp(double x) {if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1;}
Vector operator + (Vector A, Vector B) {return Vector(A.x+B.x, A.y+B.y);}
Vector operator - (Vector A, Vector B) {return Vector(A.x-B.x, A.y-B.y);}
Vector operator * (Vector A, double k) {return Vector(A.x*k, A.y*k);}
Vector operator / (Vector A, double k) {return Vector(A.x/k, A.y/k);}
double Dot(Vector A, Vector B) {return A.x*B.x + A.y*B.y;}
double Cross(Vector A, Vector B) {return A.x*B.y - A.y*B.x;}
double Length(Vector A) {return sqrt(A.x*A.x + A.y*A.y);}
double _Angle(Vector A, Vector B) {return acos(Dot(A, B) / Length(A) / Length(B));}
Vector Normal(Vector A) {return Vector(-A.y/Length(A), A.x/Length(A));} //逆时针90

void GetSegmentBisector(Point A, Point B, Point &C, Vector &v)
{
	C = (A + B) / 2;
	v = Normal(B - A);
}

Point _GetLineIntersection(Point P, Vector v, Point Q, Vector w)
{
	Vector u = P - Q;
	double t = Cross(w, u) / Cross(v, w);
	return P + v*t;
}	

Point GetCircle(Point A, Point B, Point C)
{
	Point P, Q;
	Vector v, w;
	GetSegmentBisector(A, B, P, v);
	GetSegmentBisector(A, C, Q, w);
	return _GetLineIntersection(P, v, Q, w);
}

double area(double r, double a)
{
	return r * r * sin(a) / 2;
}

Point a[5], c;
double r, ang[5], angle;
int n;

int main()
{
	while (scanf("%lf%lf%lf%lf%lf%lf", &a[0].x, &a[0].y, &a[1].x, &a[1].y, &a[2].x, &a[2].y) == 6)
	{
		a[3] = a[0];
		c = GetCircle(a[0], a[1], a[2]);
		r = Length(c - a[0]);
		for (int i=0;i<3;i++) ang[i] = _Angle(a[i]-c, a[i+1]-c);
		n = 1;
		while (n < 100)
		{
			if (dcmp(sin(n * ang[0] / 2)) == 0 && dcmp(sin(n * ang[1] / 2)) == 0 && dcmp(sin(n * ang[2] / 2)) == 0) break;
			n++;
		}
		angle = 2 * PI / n;
		printf("%.8lf\n", n * area(r, angle));
	}	
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值