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

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint() {
int Ret = ;
char Ch = ' ';
while(!(Ch >= '' && Ch <= '')) Ch = getchar();
while(Ch >= '' && Ch <= '') {
Ret = Ret*+Ch-'';
Ch = getchar();
}
return Ret;
} const int N = ;
const DB pi = acos(-1.0), Eps = 1e-;
struct Sphere {
DB High, R; inline void Read() {
scanf("%lf%lf", &High, &R);
} inline DB Calc(DB H) {
DB D = min(*R, max(0.0, H-High+R)), Ret;
Ret = pi*(R*D*D-D*D*D/);
return Ret;
}
} S[N];
struct Cube {
DB High, Width, Length, Height; inline void Read() {
scanf("%lf%lf%lf%lf", &High, &Width, &Length, &Height);
} inline DB Calc(DB H) {
DB D = min(Height, max(0.0, H-High+Height/2.0)), Ret;
Ret = Width*Length*D;
return Ret;
}
} C[N];
int n, m;
DB Width, Length, V, Ans; inline void Solve(); inline void Input() {
int TestNumber;
scanf("%d", &TestNumber);
while(TestNumber--) {
scanf("%lf%lf%lf%d%d", &Width, &Length, &V, &n, &m);
For(i, , n) C[i].Read();
For(i, , m) S[i].Read();
Solve();
}
} inline DB Calc(DB H) {
DB Ret = Width*Length*H;
For(i, , n) Ret -= C[i].Calc(H);
For(i, , m) Ret -= S[i].Calc(H);
return Ret;
} inline DB Work() {
DB Left = , Right = 1.0*INF, Mid, TmpV;
while(Right-Left >= Eps) {
Mid = (Right+Left)/2.0;
TmpV = Calc(Mid);
if(TmpV+Eps >= V) Right = Mid;
else Left = Mid;
}
return Right;
} inline void Solve() {
Ans = Work();
printf("%.6lf\n", Ans);
} int main() {
#ifndef ONLINE_JUDGE
SetIO("K");
#endif
Input();
//Solve();
return ;
}
上一篇:OC中NSFileManager


下一篇:安装python包时遇到"error: Microsoft Visual C++ 9.0 is required"的简答