fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve (int tc) {
  5. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  6. int n = 1000, iterations = 1000;
  7.  
  8. int favorable = 0, total = 0;
  9. while (iterations--) {
  10. set<int> s;
  11. for (int i = 1; i <= n; i++)
  12. s.insert(i);
  13.  
  14. while (s.size() > 1) {
  15. vector<int> curr(s.begin(), s.end());
  16. int n = curr.size();
  17.  
  18. set<int> killed;
  19.  
  20. for (int i = 0; i < n; i++) {
  21. int j = rng() % (n - 1);
  22. if (j >= i)
  23. j++;
  24.  
  25. killed.insert(curr[j]);
  26. }
  27.  
  28. for (int i : killed)
  29. s.erase(i);
  30. }
  31.  
  32. total++;
  33. if (s.size() == 1)
  34. favorable++;
  35. }
  36.  
  37. cout << (double)favorable / (double)total << '\n';
  38. }
  39.  
  40. signed main () {
  41. int t = 1;
  42. // cin >> t;
  43. for (int i = 1; i <= t; i++) {
  44. solve(i);
  45. }
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0.42s 5320KB
stdin
Standard input is empty
stdout
0.463