标签:style blog http io ar color os sp strong
题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小。
思路 : 分三种情况讨论
1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #define PI 3.1415926535897932384626433 5 6 double insection(double x1,double y1,double x2,double y2,double r1,double r2) 7 { 8 double distance=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); 9 //相离 10 if(r1+r2<distance) return 0.0 ; 11 //内含 12 else if(abs(r2-r1) >= distance) 13 { 14 if(r2>=r1) return PI*r1*r1; 15 else return PI*r2*r2; 16 } 17 //相交 18 else 19 { 20 double angle1=2*acos((r1*r1+distance*distance-r2*r2)/2/r1/distance); 21 double angle2=2*acos((r2*r2+distance*distance-r1*r1)/2/r2/distance); 22 double ans=r1*r1*angle1/2+r2*r2*angle2/2-r1*r1*sin(angle1)/2-r2*r2*sin(angle2)/2; 23 return ans ; 24 } 25 return 0 ; 26 } 27 int main() 28 { 29 double x1,y1,r1,x2,y2,r2 ; 30 while(~scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&r1,&x2,&y2,&r2)) 31 { 32 double ans = insection(x1,y1,x2,y2,r1,r2) ; 33 printf("%.3lf\n",ans) ; 34 } 35 return 0; 36 }
POJ 2546 Circular Area(两个圆相交的面积)
标签:style blog http io ar color os sp strong
原文地址:http://www.cnblogs.com/luyingfeng/p/4130689.html