fork download
  1. #include <iostream>
  2. #include <random>
  3.  
  4. using namespace std;
  5.  
  6. default_random_engine rnd(random_device{}());
  7.  
  8. bool ok()
  9. {
  10. bool win[2] = {};
  11. uniform_int_distribution<>d(0,1);
  12. uniform_real_distribution<>r(0.0,1.0);
  13.  
  14. if (d(rnd))
  15. {
  16. win[0] = r(rnd) < 0.7;
  17. win[1] = r(rnd) < 0.6;
  18. }
  19. else
  20. {
  21. win[1] = r(rnd) < 0.7;
  22. win[0] = r(rnd) < 0.6;
  23. }
  24. return win[0] && win[1];
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30. int wins = 0, total = 1000000;
  31. for(int i = 0; i < total; ++i)
  32. if (ok()) wins++;
  33. cout << double(wins)/total << endl;
  34. }
  35.  
Success #stdin #stdout 0.06s 4804KB
stdin
Standard input is empty
stdout
0.421023