1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include <iostream> #include <cstring> #include <iomanip> #include <algorithm> #include <queue> #include <stack> #include <vector> #include <set> #include <map> #include <cmath> #include <cstdio> using namespace std; #define inf 1e18 typedef long long ll; typedef long double ld; const ll maxn = 1e5+100; const ll mod = 1e9+7; const ld pi = acos(-1.0);
ld xa,ya,za,ra,xb,yb,zb,rb; ld d,va,vb,ans,ha,hb;
int main() { ios::sync_with_stdio(false);
cin >> xa >> ya >> za >> ra >> xb >> yb >> zb >> rb;
d = sqrt( (xa-xb)*(xa-xb) + (ya-yb)*(ya-yb) + (za-zb)*(za-zb) ); va = (4.0/3.0)*pi*(ra*ra*ra); vb = (4.0/3.0)*pi*(rb*rb*rb);
if(d >= ra+rb) { ans = va+vb; } else if( d+min(ra,rb) <= max(ra,rb) ) { ans = max(va,vb); } else { ha = ra - ( ( (ra*ra) - (rb*rb) + (d*d) ) / (2*d) ); hb = rb - ( ( (rb*rb) - (ra*ra) + (d*d) ) / (2*d) );
ld vra = ( pi*ha*ha*( 3*ra-ha ) ) / 3.0; ld vrb = ( pi*hb*hb*( 3*rb-hb ) ) / 3.0;
ans = va + vb - vra - vrb; }
cout << fixed << setprecision(7) << ans << endl;
return 0; }
|