【HDOJ】2289 Cup

时间:2021-10-01 16:17:45

二分。另外,圆台体积为v = PI*(r*r+r*R+R*R)*H/3。注意精度。

 #include <cstdio>
#include <cmath> #define exp 1e-9 const double PI = acos(-1.0); int main() {
int t;
double r, R, H, v, lf, rt, mid, r0, nv;
scanf("%d", &t); while (t--) {
scanf("%lf%lf%lf%lf", &r, &R, &H, &v);
lf = ;
rt = H;
while (rt >= lf+exp) {
mid = (lf+rt)/;
r0 = mid*(R-r)/H+r;
nv = PI*(r*r+r*r0+r0*r0)*mid/;
if (fabs(nv -v) <= exp)
break;
if (nv < v)
lf = mid;
else
rt = mid;
}
printf("%.6lf\n", mid);
} return ;
}