Descriptiongiven a 100*100*100 (in millimeters) cheese block, this cheese contains n spherical small holes. It is now required to cut this cheese into s slices to make each piece equal in quality. Input
The first line contains two integers n,s, which indicates that the cheese has n small empty, to be cut into S-slice (0≤n≤10000,1≤s≤100)
the next n rows contain four positive integer r,x,y,z to describe each hole, r represents the radius, and (x, Y, z) represents the coordinate of the globe. 0≤r,x,y,z≤100,000 (unit: microns)we assume that the cut must be perpendicular to the z axis. For small holes, the holes do not overlap (but may be tangent) between the holes, and each hole is completely contained by the cheese (possibly tangent to the cheese boundary). Output
The thickness (in millimeters) of each slice is output from the boundary z=0, and the relative error or absolute error of the output answer and standard answer is not more than 1e-6.
Two-point answer, because the ball does not intersect so the volume is very good, incomplete ball volume with definite integral can be introduced formula, complete with the ball volume formula
#include <cstdio>#include<cmath>typedefLong Doubleld;ConstLD Pi=acos (-1.);intn,s;ld zs[10010],rs[10010],ps[ the];ld V=1000000; LDGet(ld x) {ld a=x*10000; for(intI=0; i<n;i++)if(zs[i]+rs[i]<=x) {a-=rs[i]*rs[i]*rs[i]* (4./3.*pi); }Else if(zs[i]-rs[i]<x) {ld Z=x-Zs[i]; A-=2./3. *pi*rs[i]*rs[i]*rs[i]+pi* (rs[i]*rs[i]*z-z*z*z/3.); } returnA;} LD cal (LD V) {ld L=0, r= -, M; while(l+1e-Ten<R) {M= (l+r) *.5; if(Get(M) <v) l=M; ElseR=l; } returnL;} LD CALs (ld x) {ld a=10000; for(intI=0; i<n;i++)if(zs[i]+rs[i]>=x&&zs[i]-rs[i]<=x) {ld Z=x-Zs[i]; A-=pi* (rs[i]*rs[i]-z*z); } returnA;}intMain () {scanf ("%d%d",&n,&s); for(intI=0, x;i<n;i++) {scanf ("%d",&x); Rs[i]=x*0.001; scanf ("%d",&x); scanf ("%d",&x); scanf ("%d",&x); Zs[i]=x*0.001; V-=rs[i]*rs[i]*rs[i]* (4./3.*pi); }ps[0]=0; for(intI=1; i<=s;i++) ps[i]=cal (i*v/s); for(intI=1; i<=s;i++) printf ("%.9lf\n", ps[i]-ps[i-1]); return 0;}
bzoj4109: [Wf2015]cutting Cheese