ZOJ 3203 bulb

Original link: http://www.cnblogs.com/GREED-VI/p/9537277.html

Face questions

  Compared wildleopard home, his brother mildleopard poorer. His house is narrow and inside his room only one light bulb. Every night, he lingered in his small house, thinking about how to make more money. One day, he found his length of shadow is changing as he walked between the bulb and the wall. A sudden idea came to mind, he wants to know the maximum length of his shadow. 
Write pictures described here

Thinking

First, divide and conquer is certainly conceivable, but it is two points or three points, we just need to think about that you know, we set up a long shadow on the ground as L1, the wall is L2, L1 increase when approached, L2 decreases when far away L1 decreases, L2 increases - this is a quadratic function, you must use the rule of thirds. 
Then let us count the length L of the first L1 = DX (X from the human to the left wall), L2 = H- (Hh) * D / X ( similar triangles). 
If you do not look be appreciated that FIG., Two blue triangle similar triangles, the ratio corresponding to the same side. 
Then look at the range of x-third of the can.
Write pictures described here

Code

1  (detail I have to be so requires code?)
 2 #include <bits / STDC ++ H.>
 . 3  the using  namespace STD;
 . 4  Double H, H, D, MID1, MID2;
 . 5  int T; 
 . 6  Double Check ( Double X)
 . 7  {
 . 8      return D-H-X + (the Hh) * D / X;
 . 9  }
 10  int main ()
 . 11  {
 12 is      CIN >> T;
 13 is      the while (T-- )
 14      {
 15          CIN >> H> > H >> D;
 16          Double= l (Hh) * D / H, D = R & lt; // note from l (Hh) * D / H start, otherwise no shadow on the wall. 
. 17          the while (L + 1E- 10 <= R & lt)
 18 is          {
 . 19              MID1 = (L + R & lt) / 2 ;
 20 is              MID2 = (R & lt MID1 +) / 2 ;
 21 is              IF (Check (MID1)> = Check (MID2)) MID2 = R & lt; the else L = MID1;  
 22 is          }
 23 is          the printf ( " % .3lf \ n- " , Check (MID1));
 24      }
 25      return  0 ;
 26 is   }

 

Reproduced in: https: //www.cnblogs.com/GREED-VI/p/9537277.html

Guess you like

Origin blog.csdn.net/weixin_30919571/article/details/94794306
ZOJ
ZOJ