标签:
http://acm.hdu.edu.cn/showproblem.php?pid=5120
题意:求两个圆环的相交面积。
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 using namespace std; 6 7 int t; 8 double r,R; 9 struct point 10 { 11 double x,y; 12 double r; 13 }; 14 15 double circle_area(point a,point b) 16 { 17 double s,d,t,t1; 18 d=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); 19 if(d>=a.r+b.r) s=0; 20 else if(d<=fabs(a.r-b.r)) s=min(acos(-1.0)*a.r*a.r,acos(-1.0)*b.r*b.r); 21 else 22 { 23 t=(a.r*a.r+d*d-b.r*b.r)/2.0/d; 24 t1=sqrt(a.r*a.r-t*t); 25 s=-d*t1+a.r*a.r*acos(t/a.r)+b.r*b.r*acos((d-t)/b.r); 26 } 27 return s; 28 } 29 30 int main() 31 { 32 scanf("%d",&t); 33 for(int cas=1; cas<=t; cas++) 34 { 35 scanf("%lf%lf",&r,&R); 36 point st1,st2,st3,st4; 37 double x,y; 38 scanf("%lf%lf",&x,&y); 39 st1.x=st2.x=x; 40 st1.y=st2.y=y; 41 st1.r=r; 42 st2.r=R; 43 scanf("%lf%lf",&x,&y); 44 st3.x=st4.x=x; 45 st3.y=st4.y=y; 46 st3.r=r; 47 st4.r=R; 48 double ans=0; 49 ans+=circle_area(st2,st4); 50 ans-=circle_area(st1,st4); 51 ans-=circle_area(st2,st3); 52 ans+=circle_area(st1,st3); 53 printf("Case #%d: %.6lf\n",cas,ans); 54 } 55 return 0; 56 }
标签:
原文地址:http://www.cnblogs.com/fanminghui/p/4233616.html