Advertisement
shamiul93

LightOJ 1062 - Crossed Ladders

Feb 27th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. /**
  2. @author - Rumman BUET CSE'15
  3. 27-2-2017
  4.  
  5. Problem - 1062 - Crossed Ladders
  6.  
  7. link - http://www.lightoj.com/volume_showproblem.php?problem=1062
  8.  
  9. Concept:
  10.  
  11.     It's a famous bisection problem for me and not many people has solved it.
  12.     But I could solve it in half an hour when I didn't become a "Coder".
  13.     So, pretty special for me.
  14.  
  15.     Whatever, This is mainly a mathematical problem.
  16.  
  17.     We know a(x) , b(y) , c . By bisection we will continuously take a value of W.
  18.     At first , calculate the angles between W and x . Same for W and y.
  19.     by these angles you can calculate height of buildings p and q .
  20.  
  21.     from Similar Angle Triangle formulas,
  22.         we get ,
  23.  
  24.             c/p = m / w ; [ m is one part of W after intersecting C ]
  25.         and for other part ,
  26.  
  27.             c / q = (W - m ) / W = 1 - m/W ;
  28.         From these 2 eqn , we get ,
  29.  
  30.             c/q = 1 - c/p ;
  31.             => c = 1 / (1/p + 1/q) ;
  32.  
  33.         ***Bisection:
  34.  
  35.             For this , we will take continuously changing value for W.
  36.             The highest value of W can be p+q - d ; because , when the ladders
  37.             touch the land , it will be the highest W. but we minus 'd' from it
  38.             because we don't want to make 'c' = 0 .
  39.  
  40.         ***Condition:
  41.  
  42.             We can observe that, if W increases , C decreases because , while
  43.             W increasing , the intersecting point is coming down. So,
  44.  
  45.             "THE RELATION BECOMES OPPOSITE TO OTHER PROBLEMS."
  46.  
  47. */
  48.  
  49. #include<bits/stdc++.h>
  50. using namespace std ;
  51. #define ll long long
  52. #define fo freopen("out.txt","w",stdout)
  53. #define fi freopen("in.txt","r",stdin)
  54. #define d 0.000000001
  55. #define isprime false
  56.  
  57. double a , b , c , p , q , w ;
  58.  
  59. double formula()
  60. {
  61.     double t1 , t2 , C ;
  62.     t1 = acos(w*1.0 / a) ;
  63.     p = a * sin(t1) ;
  64.  
  65.     t2 = acos(w*1.0 / b) ;
  66.     q = b * sin(t2) ;
  67.  
  68.     C = 1.0 / ( (1.0 / p) + (1.0 / q) ) ;
  69.     return C ;
  70. }
  71.  
  72. int main()
  73. {
  74.     ll T , t = 0 ;
  75.     scanf("%lld",&T);
  76.  
  77.     while(T--)
  78.     {
  79.         t++ ;
  80.         scanf("%lf %lf %lf",&a , &b , &c);
  81.  
  82.         double hi , lo , h ;
  83.  
  84.         lo = d ;
  85.         hi = a+b-d ;
  86.  
  87.         while(hi - lo > d)
  88.         {
  89.             w = (lo+hi) / 2.0 ;
  90.             h = formula();
  91.  
  92.             if(h > c)
  93.             {
  94.                 lo = w ;
  95.             }
  96.             else
  97.             {
  98.                 hi = w ;
  99.             }
  100.         }
  101.  
  102.         printf("Case %lld: %.10f\n",t , w) ;
  103.  
  104.     }
  105.  
  106.     return 0 ;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement