Light Bulb time limit:1 Second Memory limit:32768 KB
Compared to Wildleopard's wealthiness, his brother Mildleopard is rather poor. His house is narrow and he have only one light bulb in the He house. Every night, he is wandering in his incommodious house, and thinking of how to earn. One day, he found that's the length of his shadow is changing from time to time while walking between the light bulb and th E wall of his house. A Sudden thought ran through his mind and he wanted to know the maximum length of his shadow.
Input
The first line of the input contains an integer t (t <=), indicating the number of cases.
Each test case contains three real numbers h, H and D on one line. H is the height of the bulb while H is the height of mildleopard. D is distance between, the light bulb and the wall. All numbers is in range from 10-2 to 103, both inclusive, and h-h>= 10-2.
Output
For each test case, the output of the maximum length of Mildleopard ' s shadow on one line, accurate up to three decimal places.
Sample Input
3
2 1 0.5
2 0.5 3
4 3 4
Sample Output
1.000
0.750
4.000
Analysis: When a person from the wall just have a shadow on the right to walk to the wall, the shadow of the total length of the shadow on the wall of the convex function
Three-point shadow on the wall long ...
Code:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const double lim=1e-6;
Double l,r;
Double h,h,d;
int test;
Double calc (double x)
{
return x+ (d* (h-x)/(H-x));
}
Double sf ()
{
double m1,m2,mid;
Do
{
mid= (r-l)/3;
M1=l+mid;m2=r-mid;
if (Calc (M1) <calc (m2)) l=m1; else r=m2;
} while (R-l>lim);
Return calc (l);
}
void ReadData ()
{
freopen ("zoj3203.in", "R", stdin);
Freopen ("Zoj3203.out", "w", stdout);
scanf ("%d", &test);
while (test--)
{
scanf ("%lf%lf%lf", &h,&h,&d);
L=0;r=h;
printf ("%.3lf\n", SF ());
}
}
int main ()
{
readdata ();
return 0;
}