Compared to wildleopard‘s wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, thinking of how to earn more money. One day, he found that the length of his shadow was changing from time to time while walking between the light bulb and the 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 <= 100), indicating the number of cases.Each test case contains three real numbers H, h and D in one line. H is the height of the light bulb while h is the height of mildleopard. D is distance between the light bulb and the wall. All numbers are in range from 10-2 to 103, both inclusive, and H - h >= 10-2.
Output
For each test case, output the maximum length of mildleopard‘s shadow in 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
Author:guan, Yao
Source:the 6th Zhejiang Provincial Collegiate Programming Contest
Submit Status
Three-way, in a certain position, the lamp, the head of the person and the corner 3.1 line, from this point a began to walk to the corner, shadow length first increase and decrease, is a convex function, can be solved by the three-point method
Obviously A = D? (H? h ) H , each time the shadow length obtained is l e n = (D?x )+H ? D? (H? h ) x
Then three points can be solved, pay attention to the accuracy
/************************************************************************* > File Name:ZOJ3203.cpp > Auth Or:alex > Mail: [email protected] > Created time:2015 April 05 Sunday 15:23 34 seconds ******************************** ****************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-9;typedef Long LongLL;typedefPair <int,int> PLL;DoubleH, H, D;DoubleCalcDoublex) {returnH + d-x-D * (h-h)/x;}intMain () {intTscanf("%d", &t); while(t--) {scanf("%LF%LF%LF", &h, &h, &d);DoubleL = d * (h-h)/H, r = D;DoubleMid, Midmid, Midmidarea, Midarea; while(L + EPS <= r) {mid = (L + r)/2; Midmid = (mid + R)/2; Midarea = Calc (mid); Midmidarea = Calc (midmid);if(Midarea >= Midmidarea) {r = Midmid; }Else{L = mid; } }printf("%.3f\n", Calc (l)); }return 0;}
Zoj3203--light Bulb (three-part method)