题意:有一个无穷高的长方体,里面有一些球和小的长方体,然后往大的长方体里面倒水,水只能填充到间隙里面,问水能填多高。 告诉的有 ,水的体积,大的长方体的长和宽,以及每个小的长方体的中心的高度,及它的长宽高,和球的中心的高度以及球的半径。
There is a huge cubiod house with infinite height. And there are some spheres and some cuboids in the house. They do not intersect with others and the house. The space inside the house and outside the cuboids and the spheres can contain water.
Bob wants to know when he pours some water into this house, what's the height of the water level based on the house's undersurface.
Input
The first line is a integer T (1 ≤ T ≤ 50), the number of cases.
For each case:
The first line contains 3 floats w, l (0 < w, l < 100000), the width and length of the house, v (0 < v < 1013), the volume of the poured water, and 2 integers, m (1 ≤ m ≤ 100000), the number of the cuboids, n (1 ≤ n ≤ 100000), the number of the spheres.
The next m lines describe the position and the size of the cuboids.
Each line contains z (0 < z < 100000), the height of the center of each cuboid, a (0 < a < w), b (0 < b < l), c, the width, length, height of each cuboid.
The next n lines describe the position and the size of the spheres, all these numbers are double.
Each line contains z (0 < z < 100000), the height of the center of each sphere, r (0 < 2r < w and 2r < l), the radius of each sphere.
Output
For each case, output the height of the water level in a single line. An answer with absolute error less than 1e-4 or relative error less than 1e-6 will be accepted. There're T lines in total.
Sample Input
1 1 1 1 1 1 1.5 0.2 0.3 0.4 0.5 0.5
Sample Output
1.537869
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn = 1e5+6;
const double PI = acos(-1.0);
struct sphere
{
double z,r;
}s[maxn];
struct cuboids
{
double z,l,w,h;
}c[maxn];
int n,m;
double w,l,v;
double cal(double h)
{
int i,j;
double ret=0;
for(i=1;i<=m;i++)
{
if(h<=c[i].z-c[i].h/2.0)
continue ;
if(h>=c[i].z+c[i].h/2.0)
{
ret+=c[i].l*c[i].w*c[i].h;
continue ;
}
if(h>=c[i].z)
{
ret+=(c[i].l*c[i].w*c[i].h)/2.0;
ret+=(c[i].l*c[i].w*(h-c[i].z));
continue ;
}
else
{
ret+=(c[i].l*c[i].w*(c[i].h/2.0-(c[i].z-h)));
continue ;
}
}
for(i=1;i<=n;i++)
{
if(h<=s[i].z-s[i].r)
continue ;
if(h>=s[i].z+s[i].r)
{
ret+=4/3.0*PI*s[i].r*s[i].r*s[i].r;
continue ;
}
double H;
if(h>=s[i].z)
H=s[i].r+h-s[i].z;
else
H=s[i].r-(s[i].z-h);
ret+=PI*H*H*(s[i].r-H/3.0);
}
return l*w*h-ret;
}
double Find()
{
double down=0,mid,up=1000000;
while(up-down>=0.0000001)
{
mid=(down+up)/2.0;
if(v<cal(mid))
up=mid;
else
down=mid;
}
return mid;
}
int main()
{
int ncase,i,j;
scanf("%d",&ncase);
while(ncase--)
{
scanf("%lf%lf%lf%d%d",&w,&l,&v,&m,&n);
for(i=1;i<=m;i++)
scanf("%lf%lf%lf%lf",&c[i].z,&c[i].l,&c[i].w,&c[i].h);
for(i=1;i<=n;i++)
scanf("%lf%lf",&s[i].z,&s[i].r);
printf("%.6lf\n",Find());
}
return 0;
}