Advertisement
shamiul93

LightOJ 1043 - Triangle Partitioning

Feb 27th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. /**
  2. @author - Rumman BUET CSE'15
  3.  
  4. problem - 1043 - Triangle Partitioning
  5.  
  6. link - http://www.lightoj.com/volume_showproblem.php?problem=1043
  7.  
  8. concept -
  9.  
  10. Binary search / Bisection.
  11. It is a easy problem of bisection.
  12. You can understand it without explanation.
  13. Whatever ,
  14.     Take length - 0.000000001 as hi
  15.     and  0 + 0.000000001 as lo
  16.     otherwise , AD will be '0' or full AB which is not acceptable.
  17.     because , then ABC will be not a triangle or r will  be infinity.
  18.  
  19. */
  20.  
  21. #include<bits/stdc++.h>
  22. using namespace std ;
  23. #define ll long long
  24. #define d 0.00000001
  25.  
  26. int main()
  27. {
  28.     double AB, AC, BC, r ;
  29.     ll T, t = 0 ;
  30.  
  31.     scanf("%lld",&T);
  32.  
  33.     while(T--)
  34.     {
  35.         t++ ;
  36.        
  37.         /**
  38.             for scanning double data ,
  39.                 you have to use
  40.                 %lf.
  41.                 not %f .
  42.             Be careful in these issues.
  43.        
  44.         */
  45.         scanf("%lf %lf %lf %lf",&AB, &AC, &BC,&r );
  46.        
  47. //        cout << AB << " " << AC << " " << BC << " " << r << endl ;
  48.         double s, ADE, ABC ;
  49.         s = 0.5 * (AB + AC + BC);
  50.         ABC = sqrt(1.0 * s*(s-AB)*(s-AC)*(s-BC));
  51.  
  52.         double  hi , lo , mid , AD , DE , AE , trap , R ;
  53.  
  54.         hi = AB - d ;
  55.         lo = d ;
  56.         ll k = 0 ;
  57.         while(hi - lo > d)
  58.         {
  59.             AD = (hi+lo)/2.0 ; /// mid == AD
  60.             DE = AD * 1.0 *BC /AB ;
  61.             AE = AD * 1.0 *AC /AB ;
  62.             s = 0.5 * (AD + DE + AE);
  63.             ADE = sqrt(1.0 * s*(s-AD)*(s-DE)*(s-AE));
  64.             trap = ABC - ADE ;
  65.             R = ADE *1.0 / trap ;
  66.  
  67.             if(R > r)
  68.             {
  69.                 hi =  AD ;
  70. //                cout << "hi " << hi << endl  ;
  71.             }
  72.             else
  73.             {
  74.                 lo = AD ;
  75. //                cout << "lo " << lo << endl ;
  76.             }
  77.         }
  78.         /**
  79.             for precision issue in double, you have to use %.8f -
  80.             that means 'f' ;
  81.             not 'lf' .
  82.         */
  83.         printf("Case %lld: %.11f\n",t , AD);
  84.  
  85.     }
  86.  
  87.     return 0 ;
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement