HDU 5120 Intersection (求圆环相交面积)
题意:给定圆环的内径r和外径R,以及2个相同圆环的圆心,求两个圆环的相交面积。
思路:
S = A大B大 - A大B小 - A小B大 + A小B小。(A表示A环,大表示大圆,B同)
1 #include <iostream> 2 #include <queue> 3 #include <stack> 4 #include <cstdio> 5 #include <vector> 6 #include <map> 7 #include <set> 8 #include <bitset> 9 #include <algorithm> 10 #include <cmath> 11 #include <cstring> 12 #include <cstdlib> 13 #include <string> 14 #include <sstream> 15 #include <time.h> 16 #define x first 17 #define y second 18 #define pb push_back 19 #define mp make_pair 20 #define lson l,m,rt*2 21 #define rson m+1,r,rt*2+1 22 #define mt(A,B) memset(A,B,sizeof(A)) 23 using namespace std; 24 typedef long long LL; 25 typedef unsigned long long ull; 26 const double PI = acos(-1); 27 const int N=1e6+10; 28 const LL mod=1e9+7; 29 const int inf = 0x3f3f3f3f; 30 const LL INF=0x3f3f3f3f3f3f3f3fLL; 31 const double eps=1e-8; 32 struct point 33 { 34 double x,y; 35 point(){} 36 point(double _x,double _y) 37 { 38 x=_x; 39 y=_y; 40 } 41 }; 42 double dis(point a,point b) 43 { 44 return sqrt((a.x-b.x)*(a.x-b.x)+(b.y-a.y)*(b.y-a.y)); 45 } 46 double cal(point c1,double r1,point c2,double r2) 47 { 48 double d=dis(c1,c2); 49 if(r1+r2<d+eps)return 0; 50 if(d<fabs(r1-r2)+eps) 51 { 52 double r=min(r1,r2); 53 return PI*r*r; 54 } 55 double x=(d*d+r1*r1-r2*r2)/(2*d); 56 double t1=acos(x/r1); 57 double t2=acos((d-x)/r2); 58 return r1*r1*t1+r2*r2*t2-d*r1*sin(t1); 59 } 60 int main() 61 { 62 #ifdef Local 63 freopen("data.h","r",stdin); 64 #endif 65 //ios::sync_with_stdio(false); 66 //cin.tie(0); 67 int cas=1,T,n,m; 68 scanf("%d",&T); 69 while(T--) 70 { 71 double r,R,ans; 72 struct point p,q; 73 cin>>r>>R; 74 cin>>p.x>>p.y; 75 cin>>q.x>>q.y; 76 if(dis(p,q)>=2*R)ans=0; 77 else 78 { 79 if(dis(p,q)>=2*r) 80 { 81 ans=cal(p,R,q,R)-cal(p,r,q,R)-cal(q,r,p,R); 82 } 83 else 84 { 85 ans=cal(p,R,q,R)-cal(p,r,q,R)-cal(q,r,p,R)+cal(q,r,p,r); 86 } 87 } 88 printf("Case #%d: %lf\n",cas++,ans); 89 } 90 #ifdef Local 91 cerr << "time: " << (LL) clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl; 92 #endif 93 return 0; 94 }