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
32 1 0.52 0.5 34 3 4
Sample Output
1.0000.7504.000
1#include <stdio.h>2#include <math.h>3 DoubleHsDoubleHDoubleHDoubleDDoubleX)4 {5 returnd* (h-x)/(h-x) +x;//defines the length function, where X is the projection length of the person on the wall.6 }7 intMain ()8 {9 intN;Tenscanf"%d",&n); One while(n--) A { - Doublea,b,c; -scanf"%LF%LF%LF",&a,&b,&c); the DoubleMid,midmid,l=0, r=b; - Do - { -Mid= (L+R)/2; +Midmid= (MID+R)/2; - if(HS (A,B,C,MID) >HS (A,B,C,MIDMID)) +R=Midmid; A Else atL=mid; -} while(r-l>1e-9); -printf"%.3lf\n", HS (A,b,c,mid)); - } - return 0; -}
The main idea is the three-part method to find the maximum value of the function, but to pay attention to precision I am accurate to 1e-6 WA, but also drunk!
It is recommended to be accurate to 1e-9!
Light bulb--zoj3203 (three-part method)