帮忙看看,圆面积计算的问题
roblem A:Area of CirclesTime Limit:1000MS Memory Limit:65536K
Total Submit:101 Accepted:24
Description
There are two circles on the plane. Now you must to calculate the area which they cover the plane. For example, in Figure 1, the area of the red region is the answer of this problem.
Input
The input contains multiple test cases. The first line contains an integer T describing the number of test cases. Each case contains two lines. One line describes one circle. For each line has three integers x, y, r, indicating the coordinate of the centre and radius. All the numbers are separated by spaces. All the input integers are within the range of [-1000, 1000].
Output
For each test case, output one line containing a number with 3 digits after decimal point representing the answer describing above.
Sample Input
2
2 2 2 1 4 3
2 2 1 -2 -2 1
Sample Output
32.462
6.283
帮忙看看,为什么在acm.zstu.总是不过
下面是代码
#include<stdio.h>
#include<math.h>
main()
{
float r1,r2,x1,x2,y1,y2;
int t;
while(scanf("%d",&t)!=EOF)
{while(t--)
{
scanf("%f%f%f%f%f%f",&x1,&y1,&r1,&x2,&y2,&r2);
float g,h;
g=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
h=r1*r1-r2*r2;
float d1,d2,s1,s2,s;
if(g>=r1+r2)
s=acos(-1)*r1*r1+acos(-1)*r2*r2;
else
{
if(g<=fabs(r1-r2))
{
if(r1>=r2)
s=acos(-1)*r1*r1;
else
s=acos(-1)*r2*r2;
}
else
{
d1=(g+h/g)/2.0;
d2=(g-h/g)/2.0;
s1=acos(d1/r1)*r1*r1-d1*(sqrt(r1*r1-d1*d1));
s2=acos(d2/r2)*r2*r2-d2*(sqrt(r2*r2-d2*d2));
s=acos(-1)*r1*r1+acos(-1)*r2*r2-s1-s2;
}
}
printf("%.3f\n",s);
}
}
}