HDU-1798 Tell me the area(数学)

来源:互联网 发布:测试端口通不通命令 编辑:程序博客网 时间:2024/06/07 09:30

Tell me the area

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3183 Accepted Submission(s): 1034

Problem 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 2
2 2 1

Sample Output
0.108

求 2圆相交面积啊 套公式 嗯。。。。。。。。。 又在做水题

code:

#include<bits/stdc++.h>using namespace std;#define PI acos(-1.0)int main(){    double x1,y1,r1,x2,y2,r2;    while(~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2))    {        double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));        double ans,ans1,ans2;        if(d>=r1+r2)            ans=0;        else if(d<=fabs(r1-r2))        {            double r;            r=r1<r2?r1:r2;            ans=r*r*PI;        }        else        {            ans1=acos((r1*r1+d*d-r2*r2)/(2*r1*d));            ans2=acos((r2*r2+d*d-r1*r1)/(2*r2*d));            ans=r1*r1*ans1 + r2*r2*ans2 - r1*r1*cos(ans1)*sin(ans1) - r2*r2*cos(ans2)*sin(ans2);        }        printf("%.3lf\n",ans);    }    return 0;}
原创粉丝点击