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

要点

  • 各点肯定都在外接圆上,边越多越接近圆面积,所以要最小面积应当取可能的最少边数。
  • 给三角形求外接圆半径公式:\(R=\frac{abc}{4S}\)
  • 三个角度对应的圆心角取gcd即是要求的正多边形的一个角度,然后求面积即可。注意三个圆心角的求法是三个内角乘2.
#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);
}
posted @ 2019-05-26 10:28  AlphaWA  阅读(242)  评论(0编辑  收藏  举报