Advertisement
shamiul93

LightOJ 1137 - Expanding Rods

Mar 1st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. /**
  2. @author - Rumman BUET CSE'15
  3. Problem - 1137 - Expanding Rods
  4. Link - http://www.lightoj.com/volume_showproblem.php?problem=1137
  5.  
  6. Concept-
  7.  
  8.     ** It's mainly a geometric problem. May be tough may be not.
  9.     ** ( It's another special one for me. My friend and teammate in 2017 Pranto gave me this problem
  10.         when I was not that extreme level coder. I solved it in <= 20 minutes. It felt good.
  11.         Idea was good too. :3 )
  12.  
  13.     ** We will run binary search on radius of the arc from l/2 ( it's the lowest because
  14.        if the radius is smaller than it then , the circle would not touch the chord's 2 ends.)
  15.         to 10000(as high as possible).
  16.  
  17.     ** distance from center to the chord and center angle of
  18.        the arc can be calculated by pethagoras.
  19.  
  20.     ** When s=r*theta is equal to new L , then it's the answer.
  21.  
  22. */
  23.  
  24.  
  25. #include<bits/stdc++.h>
  26. using namespace std ;
  27. #define ll long long
  28. #define fo freopen("out.txt","w",stdout)
  29. #define fi freopen("in.txt","r",stdin)
  30. #define DEBUG printf("hi\n");
  31. #define DEBUG2 printf("bi\n");
  32. #define di 0.00000001
  33.  
  34. double  L, N, C, Lnew, r ;
  35.  
  36.  
  37. using namespace std ;
  38. int main()
  39. {
  40. //    fi ;
  41. //    fo ;
  42.     ll T, t = 0 ;
  43.     double ans ;
  44.     scanf("%lld ",&T) ;
  45.  
  46.     while(T--)
  47.     {
  48.         t++ ;
  49.         scanf("%lf %lf %lf", &L, &N, &C) ;
  50.         Lnew = ( 1.0 + N*C )* L ;
  51.  
  52.         r = L / 2.0 ;
  53.  
  54.         double hi, lo, mid, s = 0, per, halfang, ang  ;
  55.  
  56.         lo = r ;
  57.         hi = 100000 ;
  58.         ll k = 0 ;
  59.  
  60.         /// However efficient binary search is, we know bisection is not exactly accurate
  61.             /// as precision loss happens. And we know , L= L prime. , so , h = 0. So, we take it
  62.             /// particularly.
  63.         if(L == Lnew)
  64.         {
  65.             ans = 0 ;
  66.         }
  67.         else
  68.         {
  69.             while(k < 66)
  70.             {
  71.                 k++ ;
  72.                 mid = (lo + hi) / 2.0 ;
  73.                 per = sqrt( 1.0*mid*mid - r*r) ;
  74.                 ang = 2.0  * asin(r *1.0 / mid) ;
  75.                 s = mid * ang ;
  76.  
  77.                 if(s > Lnew )
  78.                 {
  79.                     lo = mid ;
  80.                 }
  81.                 else
  82.                 {
  83.                     hi = mid ;
  84.                 }
  85.             }
  86.  
  87.             ans = mid - per ;
  88.  
  89.         }
  90.  
  91.  
  92.  
  93.         printf("Case %lld: %.10f\n",t, ans) ;
  94.  
  95.     }
  96.  
  97.     return 0 ;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement