对于这种水题,我只想说:
为啥精度只有开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;
}