Advertisement
kokokozhina

Untitled

Mar 21st, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>//bug
  2. #include <stdio.h>
  3. #include <algorithm>
  4. #include <iomanip>
  5. #include <math.h>
  6.  
  7. using namespace std;
  8.  
  9. double c, t;
  10.  
  11. bool can(double x)
  12. {
  13.     double val = c*log(x)/log(2)*x;
  14.     if(val < t|| ceil(val) == int(val) && int(val) == t)
  15.         return true;
  16.     return false;
  17. }
  18.  
  19. void bs()
  20. {
  21.     double l = 1.0; double r = t;
  22.     double result = 0;
  23.     for(int i = 0; i < 100; i++){
  24.         double mid = (l + r) / 2;
  25.         if(can(mid)) l = mid;
  26.         else r = mid;
  27.         result = r;
  28.     }
  29.  
  30.  
  31.     cout << fixed << showpoint << setprecision(10) << result << endl;
  32. }
  33.  
  34. int main()// c · n · log(n);zадано максимальное время работы t,
  35. //найдите такое наибольшее вещественозначное n, что алгоритм проработает не больше t.
  36. {
  37. #ifdef _DEBUG
  38.     freopen("input.txt", "r", stdin);
  39.     freopen("output.txt", "w", stdout);
  40. #endif
  41.     cin >> c >> t;
  42.     bs();
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement