题目描述
思路
代码
#include <cstdio>
int n;
double H, h, D, l, r, midl, midr, ans, ansl, ansr;
double calc(double x) {
return x + D * (h - x) / (H - x);
}
int main() {
scanf("%d", &n);
while (n--) {
scanf("%lf %lf %lf", &H, &h, &D);
l = 0, r = h;
while (r - l > 1e-6) {
midl = l + (r - l) / 3.0;
midr = r - (r - l) / 3.0;
ansl = calc(midl), ansr = calc(midr);
if (ansl < ansr) ans = ansr, l = midl;
else ans = ansl, r = midr;
}
printf("%.3lf
", ans);
}
return 0;
}