ZOJ 3913 Bob wants to pour water (计算几何+二分)

来源:互联网 发布:软件皮肤下载 编辑:程序博客网 时间:2024/05/16 01:27
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3913

题意:有一个无穷高的长方体,里面有一些球和小的长方体,然后往大的长方体里面倒水,水只能填充到间隙里面,问水能填多高。  告诉的有 ,水的体积,大的长方体的长和宽,以及每个小的长方体的中心的高度,及它的长宽高,和球的中心的高度以及球的半径。

Bob wants to pour water

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

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 wl (0 < wl < 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

11 1 1 1 11.5 0.2 0.3 0.40.5 0.5

Sample Output

1.537869
分析:百度百科_球缺
已知:球半径R,球缺高H。我们就可以得到球缺的体积为:
V=πH^2(R-H/3)
二分答案就好了。

代码:

#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;elseH=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;elsedown=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;}


0 0
原创粉丝点击