Topic Link:
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3913
The main effect of the topic:
In a house with a long width and a height of l,w,h, there are some cubes and balls. Now pour the V-liter into the house. Some cubes and balls float and some sink under the water. Now that we know the center height of each cube and ball, ask the height of the water level in the room.
Ideas:
Two points.
You can divide the height of the water level in the room and then calculate the volume of the cubes and balls in the water, and then compare the total volume in the room with the volume of water poured into the water after the cube and the ball are submerged. If it is equal, it is the height of the request.
Here is a request: a sphere to intercept part of the volume v=π*b^2* (R-B/3). b is the distance from the spherical surface after interception.
Code:
#include <stdio.h> #include <string.h> #include <math.h> #define PI acos ( -1.0) #define EPS 0.0000000001 struct node{double z,a,b,c;}
P[100005]; struct node1{double z,r;}
Q[100005];
Double w,len,v;
int n,m;
Double cal (double x) {int i,j;
Double ans=0;
for (i=1;i<=m;i++) {if (x>=p[i].z+p[i].c/2.0) ans=ans+p[i].a*p[i].b*p[i].c;
else if (x<=p[i].z-p[i].c/2.0) ans=ans+0;
else ans=ans+p[i].a*p[i].b* (x (p[i].z-p[i].c/2.0));
for (i=1;i<=n;i++) {if (X>=Q[I].Z+Q[I].R) ANS=ANS+4.0/3*PI*Q[I].R*Q[I].R*Q[I].R;
else if (X<=Q[I].Z-Q[I].R) ans=ans+0; else if (x>q[i].z-q[i].r&&x<q[i].z) ans=ans+pi* (q[i].r+x-q[i].z) * (q[i].r+x-q[i].z) * (q[i].r-(q[i].r+
X-Q[I].Z)/3.0); else ans=ans+4.0/3*pi*q[i].r*q[i].r*q[i].r-pi* (q[i].r+q[i].z-x) * (q[i].r+q[i].z-x) * (q[i].r-(Q[I].R+Q[I].Z-X)/3.0
);
return ans;
Double Erfen (double l,double r) {double Mid,mianji; while (Fabs (l-r) ≫eps) {mid= (l+r)/2.0;
Double X=cal (mid);
Mianji=w*len*mid-x;
if (Fabs (mianji-v) <=eps) return mid;
else if (mianji<v) L=mid;
else if (mianji>v) R=mid;
return mid;
int main () {int t,i,j,k;
printf ("%.9f\n", PI);
scanf ("%d", &t);
while (t--) {scanf ("%lf%lf%lf%d%d", &w,&len,&v,&m,&n);
for (i=1;i<=m;i++) scanf ("%lf%lf%lf%lf", &p[i].z,&p[i].a,&p[i].b,&p[i].c);
for (i=1;i<=n;i++) scanf ("%lf%lf", &Q[I].Z,&Q[I].R);
Double Ans=erfen (0,10000000000005);
printf ("%.8f\n", ans);
return 0;
}