点击打开链接http://poj.org/problem?id=2546
Time Limit: 1000MS | Memory Limit: 65536K |
Total Submissions: 1843 | Accepted: 808 |
Description
Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point.
Input
In the single line of input file there are space-separated real numbers x1 y1 r1 x2 y2 r2. They represent center coordinates and radii of two circles.
Output
The output file must contain single real number - the area.
Sample Input
20.0 30.0 15.0 40.0 30.0 30.0
Sample Output
608.366
Source
Northeastern Europe 2000, Far-Eastern Subregion
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
求两圆的公共面积:
#include<stdio.h>
#include<math.h>
#define pi acos(-1)
int main()
{
double x1,y1,a,x2,y2,b,c,A,B,ans,p,s,s1,s2;
scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&a,&x2,&y2,&b);
c=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
if(a<b)
{
double t=a;
a=b;
b=t;
}
if(c>=a+b)
{
printf("0.000\n");
return 0;
}
if(c<=a-b)
{
ans=pi*b*b;
printf("%.3lf\n",ans); return 0;
}
A=acos((a*a+c*c-b*b)/(2.0*a*c));
B=acos((b*b+c*c-a*a)/(2.0*b*c));
p=(a+b+c)/2.0;
s=sqrt(p*(p-a)*(p-b)*(p-c));
A=acos((b*b+c*c-a*a)/2/b/c);
B=acos((a*a+c*c-b*b)/2/a/c);
s=sqrt(p*(p-a)*(p-b)*(p-c));
ans=a*a*B+b*b*A-2*s;
printf("%.3lf\n",ans);
return 0;
}