标签:几何
2 2 3 0 0 0 0 2 3 0 0 5 0
Case #1: 15.707963 Case #2: 2.250778
#include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const double pi = acos(-1); struct point { double x, y; }; double calc_area(point a, point b, double r1, double r2) { double d = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); if (r1 - r2 - d >= 0) { return pi * r2 * r2; } double ang1 = acos((r1 * r1 + d * d - r2 * r2) / (2 * r1 * d)); double ang2 = acos((r2 * r2 + d * d - r1 * r1) / (2 * r2 * d)); return ang1 * r1 * r1 + ang2 * r2 * r2 - 0.5 * r1 * d * sin(ang1) - 0.5 * r2 * d * sin(ang2); } int main() { int t, icase = 1; scanf("%d", &t); while (t--) { double r, R, ans = 0; point p1, p2; scanf("%lf%lf", &r, &R); scanf("%lf%lf", &p1.x, &p1.y); scanf("%lf%lf", &p2.x, &p2.y); double d = sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); printf("Case #%d: ", icase++); if (d >= (2 * R)) { printf("0.000000\n"); continue; } ans = calc_area(p1, p2, R, R); if (d >= (R + r)) { printf("%f\n", ans); continue; } ans -= 2 * calc_area(p1, p2, R, r); if (d >= (2 * r)) { printf("%f\n", ans); continue; } ans += calc_area(p1, p2, r, r); printf("%f\n", ans); } return 0; }
标签:几何
原文地址:http://blog.csdn.net/guard_mine/article/details/41620987