标签:des style blog http color java os io
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1801 Accepted Submission(s): 542
利用余弦公式计算出角度,然后通过扇形和三角形的关系求出答案即可
#include<cmath> #include<cstdio> #include<cstring> #include<stdlib.h> #include<algorithm> using namespace std; double distance(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } int main() { //freopen("in.txt","r",stdin); double PI=2*asin(1.0); double x1,y1,r1; double x2,y2,r2; double dis,r,cosa,cosb; double a,b,c,d,ans; while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&r1,&x2,&y2,&r2)!=EOF) { dis=distance(x1,y1,x2,y2); if(dis>=r1+r2||r1==0||r2==0)//两圆相离,外切时,相交面积为0 ans=0; else if(dis<=fabs(r1-r2))//两圆内含,内切时,相交面积为较小圆的面积 { r=r1<r2?r1:r2; ans=r*r*PI; } else//两圆相交时 { cosa=acos((r1*r1+dis*dis-r2*r2)/(2*r1*dis)); cosb=acos((r2*r2+dis*dis-r1*r1)/(2*r2*dis));//余弦公式求出两圆连线和半径的夹角 a=r1*r1*cosa; b=r2*r2*cosb;//扇形面积 c=r1*r1*cos(cosa)*sin(cosa); d=r2*r2*cos(cosb)*sin(cosb);//三角形面积 // s1=0.5*r1*r1*(cos1-sin(cos1)); // s2=0.5*r2*r2*(cos2-sin(cos2)); ans=(a+b)-(c+d);//这里用两个扇形的面积之和减去三角形之和,是因为相交的情况分为两个圆的圆心是否在同一个圆里两种情况 } printf("%.3lf\n",ans); } return 0; }
HDU 1798 Tell me the area (计算几何),布布扣,bubuko.com
HDU 1798 Tell me the area (计算几何)
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/clliff/p/3927563.html