2 2 3 0 0 0 0 2 3 0 0 5 0
Case #1: 15.707963 Case #2: 2.250778
题意:
给出两个相同的圆环的内径和外径,以及圆心的坐标,求两个圆环交叉部分的面积
题解:
前几天周练,数学大神1A此题,赛后,个人进行尝试,测试样例都过不去......真心比不起啊......
一个函数,参数传递是两个圆的半径,以及两个圆的圆心坐标,返回两个圆的交叉部分面积
然后就是容斥原理的一部分了:
S=S(两个外环大圆相交部分)-2* S(一个的外环和另一个的内环的相交面积)+S(两个内环的圆的相交部分)
好久没接触过几何题,感觉自己好水.......
/* http://blog.csdn.net/liuke19950717 */ #include<cstdio> #include<cmath> #include<algorithm> using namespace std; const double pi=acos(-1.0); struct node { double x,y; }; double dis(node a,node b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double circle_cross(double r1,double r2,node a,node b) { double d=dis(a,b);//两圆的间距 if(r1<r2)//保证大圆在前 { swap(r1,r2); } if(d>=r1+r2) { return 0; } if(d<=r1-r2) { return pi*r2*r2; } double deg1=acos((r1*r1+d*d-r2*r2)/(2*r1*d)); double deg2=acos((r2*r2+d*d-r1*r1)/(2*r2*d)); return deg1*r1*r1+deg2*r2*r2-r1*sin(deg1)*d; } int main() { int t; scanf("%d",&t); for(int k=1;k<=t;++k) { int r,R; node p[5]; scanf("%d%d",&r,&R); for(int i=1;i<=2;++i) { scanf("%lf%lf",&p[i].x,&p[i].y); } double d=dis(p[1],p[2]); double a=circle_cross(R,R,p[1],p[2]); double b=circle_cross(R,r,p[1],p[2]); double c=circle_cross(r,r,p[1],p[2]); double ans=a+c-2*b; printf("Case #%d: %.6f\n",k,ans); } return 0; }