题目传送门
/*
二分搜索:枚举高度,计算体积与给出的比较。
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-;
const double PI = acos (-1.0);
double r, R, H, V;
double x;
double cal(double h1) {
double u = r + (R - r) * h1 / H; //上底
double V1 = PI / 3.0 * h1 * (r * r + r * u + u * u); //圆台计算公式
return V1;
}
int main(void) { //HDOJ 2289 Cup
//freopen ("HDOJ_2289.in", "r", stdin);
int T; scanf ("%d", &T);
while (T--) {
scanf ("%lf%lf%lf%lf", &r, &R, &H, &V);
double mid;
double low = , upp = H;
while (upp - low > EPS) {
mid = (low + upp) / ;
if (cal (mid) - V > EPS) upp = mid;
else low = mid;
}
printf ("%.6f\n", mid);
}
return ;
}