标签:
2bc*cosA=b^2+c^2-a^2
/* 先吐槽一下标程π的取值范围 蒟蒻表示真没想到怎么求相交的情况,一心就想求交点,其实计算香蕉的面积 可以用扇形减去三角形 */ #include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> const double pi=3.14159265358979323846264; using namespace std; void work() { double x1,y1,r1,x2,y2,r2; scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2); double d=sqrt(abs(x1-x2)*abs(x1-x2)+abs(y1-y2)*abs(y1-y2)); if(r1+r2<=d)//相离 { double ans=r1*r1*pi+r2*r2*pi; printf("%.3lf\n",ans); return; } if(r1+r2>d&&abs(r1-r2)>=d)//内含 { double ans=max(r2,r1)*max(r2,r1)*pi; printf("%.3lf\n",ans); return; } //相交 double ans=r1*r1*pi+r2*r2*pi; double j1=acos((d*d+r1*r1-r2*r2)/(2*d*r1)); double j2=acos((d*d+r2*r2-r1*r1)/(2*d*r2)); ans-=(r1*r1*j1+r2*r2*j2); ans+=d*r1*sin(j1); printf("%.3lf\n",ans); } int main() { freopen("jh.in","r",stdin); //freopen("standing.in","r",stdin); //freopen("standing.out","w",stdout); int T;scanf("%d",&T); while(T--) { work(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/harden/p/5933057.html