Hdu--2014北京区域赛I
2014-11-29 16:50:02
思路:比赛时没想到这个小容斥。。。回来做了道圆相交模板题,然后把这题秒了。
答案 = 大圆交大圆 - 2 × 大圆交小圆 + 小圆交小圆
1 /************************************************************************* 2 > File Name: i.cpp 3 > Author: Nature 4 > Mail: 564374850@qq.com 5 > Created Time: Sat 29 Nov 2014 03:55:06 PM CST 6 ************************************************************************/ 7 8 #include <cstdio> 9 #include <cstring> 10 #include <cstdlib> 11 #include <cmath> 12 #include <vector> 13 #include <map> 14 #include <set> 15 #include <stack> 16 #include <queue> 17 #include <iostream> 18 #include <algorithm> 19 using namespace std; 20 #define lp (p << 1) 21 #define rp (p << 1|1) 22 #define getmid(l,r) (l + (r - l) / 2) 23 #define MP(a,b) make_pair(a,b) 24 typedef long long ll; 25 const int INF = 1 << 30; 26 const double eps = 1e-8; 27 const double PI = acos(-1.0); 28 29 int T; 30 double r,R; 31 double x[2],y[2]; 32 33 double Cal(double ax,double ay,double ar,double bx,double by,double br){ 34 double d = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by)); 35 if(d >= ar + br) 36 return 0.0; 37 double minr = min(ar,br); 38 if(d <= fabs(ar - br)) 39 return PI * minr * minr; 40 double a1 = acos((ar * ar + d * d - br * br) / (2.0 * ar * d)); 41 double a2 = acos((br * br + d * d - ar * ar) / (2.0 * br * d)); 42 double ans = -d * ar * sin(a1); 43 ans += a1 * ar * ar + a2 * br * br; 44 return ans; 45 } 46 47 int main(){ 48 scanf("%d",&T); 49 for(int tt = 1; tt <= T; ++tt){ 50 scanf("%lf%lf",&r,&R); 51 scanf("%lf%lf%lf%lf",&x[0],&y[0],&x[1],&y[1]); 52 printf("Case #%d: %.6f\n",tt,Cal(x[0],y[0],R,x[1],y[1],R) - 53 2.0 * Cal(x[0],y[0],r,x[1],y[1],R) + Cal(x[0],y[0],r,x[1],y[1],r)); 54 } 55 return 0; 56 }

浙公网安备 33010602011771号