ZOJ 3913 Bob wants to pour water (计算几何+二分)
来源:互联网 发布:软件皮肤下载 编辑:程序博客网 时间:2024/05/16 01:27
题意:有一个无穷高的长方体,里面有一些球和小的长方体,然后往大的长方体里面倒水,水只能填充到间隙里面,问水能填多高。 告诉的有 ,水的体积,大的长方体的长和宽,以及每个小的长方体的中心的高度,及它的长宽高,和球的中心的高度以及球的半径。
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
11 1 1 1 11.5 0.2 0.3 0.40.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;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;}
- ZOJ 3913 Bob wants to pour water (计算几何+二分)
- ZOJ 3913 Bob wants to pour water (计算几何+二分)
- ZOJ 3913 Bob wants to pour water 二分
- ZOJ 3913 Bob wants to pour water(二分)
- zoj 3913 Bob wants to pour water(二分)
- zoj 3913 Bob wants to pour water(zoj 2015年10月月赛k题)
- ZOJ 3913 Bob wants to pour water —— ZOJ Monthly, October 2015
- Zoj Just Pour the Water 2974
- ZOJ - 2974 Just Pour the Water
- zoj 2974 Just Pour the Water
- zoj 2974 Just Pour the Water 矩阵
- ZOJ - 2974 Just Pour the Water
- ZOJ 2974Just Pour the Water
- [矩阵幂运算] ZOJ 2974 Just Pour the Water
- 【矩阵快速幂】ZOJ 2974 Just Pour the Water
- ZOJ 2974 Just Pour the Water(矩阵快速幂)
- ZOJ 2974-Just Pour the Water(矩阵快速幂)
- ZOJ 1973 Just Pour the Water(矩阵快速幂)
- Java基础:成员变量与局部变量的区别
- 初始化CCB的命名规范
- HDU 4493 Tutor
- R语言实战
- Codeforces Round #318 573B. Bear and Blocks
- ZOJ 3913 Bob wants to pour water (计算几何+二分)
- 麻省理工牛人解说数学体系
- 浅析image,imagesc,imshow的用法
- springmvc工作原理
- ithetao.com试试,测试
- 014-案例开发.Storm计算网站PV
- IOS 页面传值的方法
- PHPCMS建站 - 随手记
- jsp往servlet传参