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.
Name=light_bulb_1037_ddd01.gif ">
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
32 1 0.52 0.5 34 3 4
Sample Output
1.0000.7504.000
Note the accuracy of this problem is the lowest EPS = 1e-8;
#include <cstdio>const double eps = 1e-8;double h, h, d;double f (double x) { return H (h-h) *d/x + d-x;} int main () { int t; scanf ("%d", &t); while (t--) { scanf ("%lf%lf%lf", &h, &h, &d); Double L = d-h*d/h, r = D; Double ans = -100; while (L+eps<r) { Double m1 = l + (r-l)/3; Double m2 = R-(r-l)/3; if (f (M1) <f (m2)) L = m1, ans = f (m2); else R = m2, ans = f (m1); } printf ("%.3f\n", ans); } return 0;}
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
Zoj 3203 Light Bulb, Two-thirds of the basic questions