hdu1077计算几何

根据atan函数求出β的值,再用中点坐标与β的值求出圆形的坐标。
#include <iostream> #include <cmath> const double eps = 1e-6; const int MAXN = 305; struct node { double x, y; }; struct node ps[MAXN]; int N; double dis(node a, node b) { return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2)); } node cent0(node a, node b) { double midx = (a.x + b.x) / 2; double midy = (a.y + b.y) / 2; double l = sqrt(1 - pow(dis(a, b) / 2, 2)); double dx = a.x - b.x; double dy = a.y - b.y; node po; if (dy < 1e-6) { po.x = midx; po.y = midy + l; } else { double angle = atan(dx / dy); po.x = midx + l * cos(angle); po.y = midy - l * sin(angle); } return po; } node cent1(node a, node b) { double midx = (a.x + b.x) / 2; double midy = (a.y + b.y) / 2; double l = sqrt(1 - pow(dis(a, b) / 2, 2)); double dx = a.x - b.x; double dy = a.y - b.y; node po; if (fabs(dy) < 1e-6) { po.x = midx; po.y = midy - l; } else { double angle = atan(dx / dy); po.x = midx - l * cos(angle); po.y = midy + l * sin(angle); } return po; } int main() { int T, i, j, k, max0,max1; scanf_s("%d", &T); while (T--) { scanf_s("%d", &N); for (i = 0; i < N; i++) scanf_s("%lf%lf", &ps[i].x, &ps[i].y); int ans = 1; for (i = 0; i < N; i++)//枚举O(n^2) { for (j = i + 1; j < N; j++) { if (dis(ps[i], ps[j]) >= 2) continue; node c0 = cent0(ps[i], ps[j]); node c1 = cent1(ps[i], ps[j]); for (k = 0, max0 = 0, max1 = 0; k < N; k++) { //if (N - k + max <= ans) break; double temp0 = dis(ps[k],c0); double temp1 = dis(ps[k], c1); if (temp0 <= 1.000001) { max0++; } if (temp1 <= 1.000001) { max1++; } } if (max0 > ans) { ans = max0; } if (max1> ans) { ans = max1; } } } printf("%d\n", ans); } return 0; }