poj2546 两圆相交模板(不错的模板get)

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<cmath>
 4 #include<algorithm>
 5 #define pi 3.1415926535897932384626433832795
 6 using namespace std;
 7 double area(double x1,double y1,double r1,double x2,double y2,double r2)
 8 {
 9     double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
10     double r=r1<r2?r1:r2;
11     if (d>=r1+r2) return 0;
12     if (d<=fabs(r1-r2)) return pi*r*r;
13     double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d));
14     double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d));
15     double ans=0.0;
16     ans-=r1*sin(a1)*d;
17     ans+=r1*r1*a1+r2*r2*a2;
18     return ans;
19 }
20 int main()
21 {
22     double x1,y1,r1,x2,y2,r2;
23     while (~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2))
24         printf("%.3lf\n",area(x1,y1,r1,x2,y2,r2));
25     return 0;
26 }

 题目:http://poj.org/problem?id=2546

posted on 2014-11-29 00:02  xiao_xin  阅读(169)  评论(0编辑  收藏  举报

导航