2bc*cosA=b^2+c^2-a^2
#include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> using namespace std; const double pi=3.1415926535898;//我不明白他为什么会卡精度 int t; double x1,y,r1,x2,y2,r2,s,a,b,c,k,m,w,p; int main() { scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf%lf%lf",&x1,&y,&r1,&x2,&y2,&r2); double d=sqrt((x2-x1)*(x2-x1)+(y2-y)*(y2-y); if(d>=(r1+r2))//两圆相离 s=pi*r1*r1+pi*r2*r2; else if(d<abs(r1-r2))//两圆内含 s=max(pi*r1*r1,pi*r2*r2); else//两圆相交 { s=r1*r1*pi+pi*r2*r2; k=sqrt((x1-x2)*(x1-x2)+(y-y2)*(y-y2)); w=(r1*r1+k*k-r2*r2)/(2*r1*k); p=2*acos(w); s-=((p*r1*r1)/2-sin(p)*r1*r1/2); w=(r2*r2+k*k-r1*r1)/(2*r2*k); p=2*acos(w); s-=((p*r2*r2)/2-sin(p)*r2*r2/2); } printf("%.3lf ",s); } return 0; }