标签:
2 2 3 0 0 0 0 2 3 0 0 5 0
Case #1: 15.707963 Case #2: 2.250778
#include<stdio.h> #include<math.h> #include<algorithm> using namespace std; double dis,R,r; struct point{ double x,y; }a,b; const double pi=acos(-1.0); double S(double r1,double r2){ if(dis>=(r1+r2)) return 0; //外切或不相交 double s1,s2,sit1,sit2; if(dis<=fabs(r1-r2)){ //内切或内含 r1=min(r1,r2); return pi*r1*r1; } s1=(r1*r1+dis*dis-r2*r2)/(2*r1*dis); s2=(r2*r2+dis*dis-r1*r1)/(2*r2*dis); sit1=acos(s1); sit2=acos(s2); return sit1*r1*r1+sit2*r2*r2-r1*dis*sin(sit1); } int main(){ int t,cas=0; scanf("%d",&t); while(t--){ ++cas; scanf("%lf%lf",&r,&R); scanf("%lf%lf",&a.x,&a.y); scanf("%lf%lf",&b.x,&b.y); dis=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); if(fabs(dis)<1e-7){ printf("Case #%d: %.6lf\n",cas,pi*(R*R-r*r)); continue; } double ss=0; ss=S(R,R); ss-=2*S(R,r)-S(r,r); printf("Case #%d: %.6lf\n",cas,ss); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/qq_18062811/article/details/47185239