ZOJ 3203: Light Bulb
阿新 • • 發佈:2017-07-30
pre light stream mes -- eps clas cnblogs logs
ZOJ 3203: Light Bulb
1 ///@author Sycamore, ZJNU 2 ///@date 2017-02-09 3 #include<algorithm> 4 #include<iostream> 5 #include<iomanip> 6 #define eps 1e-10 7 using namespace std; 8 double H, h, L, D; 9 double getL(double a) 10 { 11 return (h - a) / (H - a)*D + a; 12 } 13 int main()14 { 15 int T; 16 cin >> T; 17 while (T--) 18 { 19 cin >> H >> h >> D; 20 double l = 0, r = h,lmid,rmid; 21 while (r-l >= eps) 22 { 23 lmid = r / 3.0 + l * 2 / 3.0; 24 rmid = l / 3.0 + r * 2 / 3.0; 25 if(getL(lmid) -getL(rmid)>=eps)r=rmid; 26 else l=lmid; 27 } 28 cout << fixed<<setprecision(3)<<getL((r + l) / 2) << endl; 29 } 30 return 0; 31 }
ZOJ 3203: Light Bulb