T≤100,1e?2≤H,h,D≤1e3, 1e-2<=H-h
#include<cstdio>
#include<iostream>
using namespace std;
int T;
double D, h, H;
double f(double x){
if(x <= h*D/H) return x + (H - (H - h) * D / (D - x));
else return x - D + ((D - x) * H / (H - h));
}
int main(void)
{
scanf("%d", &T);
while(T--){
scanf("%lf%lf%lf", &H, &h, &D);
double l = 0, r = D;
while(r - l > 1e-11){
double bp = (r - l) / 3, l1 = l + bp, l2 = r - bp;
if(f(l1) < f(l2)) l = l1;
else r = l2;
}
printf("%.3lf
", f(l));
}
}
思路:
非常单纯的三分,除了f(x)表达式需要推导一下,其他很简单。
??2??≤??2??≤H??2??≤H,h,D≤10?3??,10?2≤H?h10^{-2} leq H-h10??2??≤H?h。