Advertisement
ProgrammerMaf

Untitled

Mar 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<stdio.h>
  5. #include<vector>
  6. #include<set>
  7. #include<map>
  8. #include<string>
  9. #include<queue>
  10. #include<math.h>
  11. #include<deque>
  12.  
  13. #define ll long long
  14. #define ld long double
  15.  
  16. using namespace std;
  17.  
  18. bool get_random(ll n) {
  19.     for (ll i = 0; i < n; i++)
  20.         if (rand() % 2)
  21.             return false;
  22.     return true;
  23. }
  24.  
  25. const ll inf = 1ll << 62;
  26. const int exp_cnt = 1000;
  27.  
  28. ll get_number(ll pwr) {
  29.     if (pwr > 62)
  30.         return inf;
  31.     return 1ll << pwr;
  32. }
  33.  
  34. const ll eps = 1ll << 12;
  35.  
  36. bool experiment(ll n) {
  37.     ll sum = 0;
  38.     for (ll i = 1; i <= n; i++) {
  39.         if (get_random(i))
  40.             sum += get_number(i);
  41.         if (sum > n * eps)
  42.             return true;
  43.     }
  44.     return false;
  45. }
  46.  
  47. bool probability(ll n) {
  48.     for (int i = 0; i < exp_cnt; i++)
  49.         if (experiment(n))
  50.             return true;
  51.     return false;
  52. }
  53.  
  54. void solve() {
  55.     ll n = 1;
  56.     ll ex = 0;
  57.     for (; ; n++) {
  58.         if (experiment(n)) {
  59.             cout << "Experiment # " << n << ". Result: explosion. Last explosion: " << ex << endl;
  60.             ex = n;
  61.         }
  62.         else
  63.             cout << "Experiment # " << n << ". Result: success. Last explosion: " << ex << endl;
  64.     }
  65. }
  66.  
  67. int main()
  68. {
  69.     solve();
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement