ZOJ 3913 Bob wants to pour water ZOJ Monthly, October 2015 - H

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
1
1 1 1 1 1
1.5 0.2 0.3 0.4
0.5 0.5
Sample Output
1.537869

Author: YANG, Xinyu; ZHAO, Yueqi

 

题意:给出一个长为l,宽为w,无限高的长方体,这个长方体,然后给出若干的球或长方体,给出它们的各种参数(包括高度),所有的球和长方体都是不重叠的(废话)

问导入v的体积的水,问水面高度多少。

分析:根据数据范围显然是一道二分水面高度,暴力验证的题目

算球的缺体的公式可以用球面锥的面积(指在球面那部分的面积)与球面面积的比减去圆锥的体积得到

球面锥的面积:2piRH,H为半径减去球心到圆锥地面的距离

没什么trick

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <cstdlib>
  4 #include <cmath>
  5 #include <deque>
  6 #include <vector>
  7 #include <queue>
  8 #include <iostream>
  9 #include <algorithm>
 10 #include <map>
 11 #include <set>
 12 #include <ctime>
 13 using namespace std;
 14 typedef long long LL;
 15 typedef double DB;
 16 #define For(i, s, t) for(int i = (s); i <= (t); i++)
 17 #define Ford(i, s, t) for(int i = (s); i >= (t); i--)
 18 #define Rep(i, t) for(int i = (0); i < (t); i++)
 19 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
 20 #define rep(i, x, t) for(int i = (x); i < (t); i++)
 21 #define MIT (2147483647)
 22 #define INF (1000000001)
 23 #define MLL (1000000000000000001LL)
 24 #define sz(x) ((int) (x).size())
 25 #define clr(x, y) memset(x, y, sizeof(x))
 26 #define puf push_front
 27 #define pub push_back
 28 #define pof pop_front
 29 #define pob pop_back
 30 #define ft first
 31 #define sd second
 32 #define mk make_pair
 33 inline void SetIO(string Name) {
 34     string Input = Name+".in",
 35     Output = Name+".out";
 36     freopen(Input.c_str(), "r", stdin),
 37     freopen(Output.c_str(), "w", stdout);
 38 }
 39 
 40 inline int Getint() {
 41     int Ret = 0;
 42     char Ch = ' ';
 43     while(!(Ch >= '0' && Ch <= '9')) Ch = getchar();
 44     while(Ch >= '0' && Ch <= '9') {
 45         Ret = Ret*10+Ch-'0';
 46         Ch = getchar();
 47     }
 48     return Ret;
 49 }
 50 
 51 const int N = 100010;
 52 const DB pi = acos(-1.0), Eps = 1e-7;
 53 struct Sphere {
 54     DB High, R;
 55     
 56     inline void Read() {
 57         scanf("%lf%lf", &High, &R);
 58     }
 59     
 60     inline DB Calc(DB H) {
 61         DB D = min(2*R, max(0.0, H-High+R)), Ret;
 62         Ret = pi*(R*D*D-D*D*D/3);
 63         return Ret;
 64     }
 65 } S[N];
 66 struct Cube {
 67     DB High, Width, Length, Height;
 68     
 69     inline void Read() {
 70         scanf("%lf%lf%lf%lf", &High, &Width, &Length, &Height);
 71     }
 72     
 73     inline DB Calc(DB H) {
 74         DB D = min(Height, max(0.0, H-High+Height/2.0)), Ret;
 75         Ret = Width*Length*D;
 76         return Ret;
 77     }
 78 } C[N];
 79 int n, m;
 80 DB Width, Length, V, Ans;
 81 
 82 inline void Solve();
 83 
 84 inline void Input() {
 85     int TestNumber;
 86     scanf("%d", &TestNumber);
 87     while(TestNumber--) {
 88         scanf("%lf%lf%lf%d%d", &Width, &Length, &V, &n, &m);
 89         For(i, 1, n) C[i].Read();
 90         For(i, 1, m) S[i].Read();
 91         Solve();
 92     }
 93 }
 94 
 95 inline DB Calc(DB H) {
 96     DB Ret = Width*Length*H;
 97     For(i, 1, n) Ret -= C[i].Calc(H);
 98     For(i, 1, m) Ret -= S[i].Calc(H);
 99     return Ret;
100 }
101 
102 inline DB Work() {
103     DB Left = 0, Right = 1.0*INF, Mid, TmpV;
104     while(Right-Left >= Eps) {
105         Mid = (Right+Left)/2.0;
106         TmpV = Calc(Mid);
107         if(TmpV+Eps >= V) Right = Mid;
108         else Left = Mid;
109     }
110     return Right;
111 }
112 
113 inline void Solve() {
114     Ans = Work();
115     printf("%.6lf\n", Ans);
116 }
117 
118 int main() {
119     #ifndef ONLINE_JUDGE 
120     SetIO("K");
121     #endif 
122     Input();
123     //Solve();
124     return 0;
125 }
View Code

 

转载于:https://www.cnblogs.com/StupidBoy/p/4886231.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值