其他分享
首页 > 其他分享> > Codeforces 1C(外接圆与正多边形)

Codeforces 1C(外接圆与正多边形)

作者:互联网

要点

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

typedef double db;
const db PI = acos(-1.0);
const db eps = 1e-2;

db x[3], y[3], len[3];

db sqr(db x) {
    return x * x;
}

db S(db a, db b, db c) {
    db p = (a + b + c) / 2;
    db res = p * (p - a) * (p - b) * (p - c);
    return sqrt(res);
}

db calc(db c, db a, db b) {
    db res = (sqr(a) + sqr(b) - sqr(c)) / 2 / a / b;
    return acos(res + 1e-8);
}

db gcd(db a, db b) {
    if (fabs(b) < eps) return a;
    return gcd(b, fmod(a, b));
}

int main() {
    for (int i = 0; i < 3; i++)
        scanf("%lf%lf", &x[i], &y[i]);

    db mul = 1.0;
    for (int i = 0; i < 3; i++) {
        int j = (i + 1) % 3;
        len[i] = sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]));
        mul *= len[i];
    }

    db R = mul / 4 / S(len[0], len[1], len[2]);
    db delta = -1, select;
    for (int i = 0; i < 3; i++) {
        db tmp = calc(len[i], len[(i + 1) % 3], len[(i + 2) % 3]);
        tmp *= 2;
        if (delta < 0)  delta = tmp;
        else    delta = gcd(tmp, delta);
    }
    db ans = sqr(R) * sin(delta) * PI / delta;
    return !printf("%.20lf\n", ans);
}

标签:return,int,sqr,db,Codeforces,len,外接圆,1C,delta
来源: https://www.cnblogs.com/AlphaWA/p/10925300.html