![](http://acm.sdibt.edu.cn/vjudge/ojFiles/hdu/data/images/C125_1007_1.jpg)
Input
Output
Sample Input
Sample Output
三种情况 acos的用法
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
using namespace std;
#define PI acos(-1)
int main()
{
double r1,r2,x1,x2,y1,y2,l,a,m,n,t,r3,d1,d2,x,s1,s2,s3,s4;
while(~scanf("%lf%lf%lf",&x1,&y1,&r1))
{
scanf("%lf%lf%lf",&x2,&y2,&r2);
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
t=r1-r2;
r3=r2;
if(t<0)
{
r3=r1;
t=-t;
}
else
;
if(a<=t)
printf("%.3f\n",PI*r3*r3);
else if(a>=r1+r2)
printf("0.000\n");
else
{
d1=(r1*r1-r2*r2+a*a)/2/a;
x=sqrt(r1*r1-d1*d1);
d2=(r2*r2-r1*r1+a*a)/2/a;
m=acos(d1/r1);
n=acos(d2/r2);
if(m<0)
m=-m;
if(n<0)
n=-n;
s1=m*r1*r1;
s2=n*r2*r2;
s3=d1*x;
s4=d2*x;
printf("%.3lf\n",s1-s3+s2-s4);
}
}
}