Tell me the area
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
There are two circles in the plane (shown in the below picture), there is a common area between the two circles. The problem is easy that you just tell me the common area.

Input
There are many cases. In each case, there are two lines. Each line has three numbers: the coordinates (X and Y) of the centre of a circle, and the radius of the circle.
Output
For each case, you just print the common area which is rounded to three digits after the decimal point. For more details, just look at the sample.
Sample Input
0 0 22 2 1
Sample Output
0.108
两圆的位置关系包括 相离、外切、相交、内切、内含。
最麻烦的是求相交的情况。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
double x1,y1,r1,x2,y2,r2,a,b,d;
double s1,s2,s3,s4;
while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2)!=EOF)
{
d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
if(d>=(r1+r2)||r1==0||r2==0)
printf("0.000\n");
else if(d<=fabs(r1-r2)&&d>=0)
{
s1=acos(-1)*r1*r1;
s2=acos(-1)*r2*r2;
if(s1>s2)
printf("%.3lf\n",s2);
else
printf("%.3lf\n",s1);
}
else
{
a=2*acos((r1*r1+d*d-r2*r2)/(2*d*r1));
b=2*acos((r2*r2+d*d-r1*r1)/(2*d*r2));
s1=0.5*a*r1*r1;
s2=0.5*b*r2*r2;
s3=0.5*r1*r1*sin(a);
s4=0.5*r2*r2*sin(b);
printf("%.3lf\n",s1+s2-s3-s4);
}
}
return 0;
}