Thirds
L changes in the shadow of two parts. Part I: the wall shadow is 0, the shadow of the growing surface, relatively simple variant, when x takes the maximum value of the first portion (x = l below) when it is taken to a first maximum value L portion; a second section, increasing the shadow of the wall, ground shadow continues to decrease, it changes a little bit more complicated than the first part, but you can still determine a sudden function on a single peak, so it can be resolved by one-third. Here are analyzed for the two parts
Left side wall and is provided to the person's position is x, the first section is a range (0 <= x <= l), is the range of the second portion (l <= x <= D), focus will be subject to conversion to Resolution function l is obtained and a second portion changes:
A first portion (seeking l):
Image taken directly to the maximum value:
Obtained by a simple calculation similar triangles: l = DD * h / H
A second portion (Resolution Function requirements of the second portion);
The shadow of the ground segment was simply Dx, focusing on the shadow on the wall, we are here to set him y
Also, as auxiliary lines, using similar triangles give y = H + D (Hh) / x;
L=D-x+H+D(H-h)/x;
After the two parts are considered good, you can write pointers, A out of this problem!
1 #include<bits/stdc++.h> 2 using namespace std; 3 int T; 4 double H,h,D; 5 double f(double x){ 6 return D-x+H+D*(h-H)/x; 7 } 8 int main(){ 9 scanf("%d",&T); 10 for(int X=1;X<=T;X++){ 11 scanf("%lf%lf%lf",&H,&h,&D); 12 double l=D-D*h/H,r=D; 13 while(r-l>=1e-3){ 14 double m1=l+(r-l)/3,m2=r-(r-l)/3; 15 if(f(m1)<f(m2))l=m1; 16 else r=m2; 17 } 18 printf("%.3lf\n",f(r)); 19 } 20 return 0; 21 }