In order to describe a nuclear action, you are asked to tell where the electrons may occur. Here we assume that the electrons only occur within a sphere whose location and radius are given. The action consists of only two atoms. Input There are multiple test cases. The first line of input is an integer T indicating the number of test cases. (0 < T ≤ 50) Each test case consists of a line containing 8 integers X1, Y1, Z1, R1, X2, Y2, Z2 and R2, describing the coordinates and the radiuses of the two atoms. The absolute value of each coordinate do not exceed 100 and 0 < R1, R2 ≤ 100. Output For each test case, output the volume of space where the electrons may occur, accurated to the nearest 0.01. Sample Input
3 0 0 0 1 0 0 2 1 0 0 0 2 0 0 2 2 0 0 0 2 0 0 2 1
Sample Output
8.38 56.55 36.00 #include<iostream> #include<cstdio> #include<cmath> using namespace std; const double pi=acos(-1.0); int x[2],y[2],z[2]; int R,r; double d; int main() { int ci;scanf("%d",&ci); while(ci--) { scanf("%d%d%d%d%d%d%d%d",&x[0],&y[0],&z[0],&R,&x[1],&y[1],&z[1],&r); double d=sqrt((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1])+(z[0]-z[1])*(z[0]-z[1])); double v1=4*pi*R*R*R/3,v2=4*pi*r*r*r/3; if(d>=R+r) { printf("%.2lf/n",v1+v2); } else if(fabs(R-r)>=d) { printf("%.2lf/n",max(v1,v2)); } else { if(R<r) swap(R,r); double insrt=(pi*(R+r-d)*(R+r-d)*(d*d+2*d*r-3*r*r+2*d*R+6*r*R-3*R*R))/(12*d); printf("%.2lf/n",v1+v2-insrt); } } return 0; } |