2bc*cosA=b^2+c^2-a^2
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/* 先吐槽一下标程π的取值范围 蒟蒻表示真没想到怎么求相交的情况,一心就想求交点,其实计算香蕉的面积 可以用扇形减去三角形 */ #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 ",ans); return; } if(r1+r2>d&&abs(r1-r2)>=d)//内含 { double ans=max(r2,r1)*max(r2,r1)*pi; printf("%.3lf ",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 ",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; }