fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int NUM_ROUNDS = 100000000;
  5.  
  6. int main() {
  7. int tot = 0;
  8. for(int test = 0; test <= NUM_ROUNDS; test++){
  9. int cards = 1;
  10. for(int round = 1;; round++){
  11. int ncards = 0;
  12. for(int i = 0; i < cards; i++){
  13. if(rand() % 4 == 0){
  14. ncards += 2;
  15. }
  16. }
  17. if(ncards == 0){
  18. tot += round;
  19. break;
  20. } else {
  21. cards = ncards;
  22. }
  23. }
  24. }
  25. cout << (double)tot / NUM_ROUNDS;
  26. }
Success #stdin #stdout 1.99s 4408KB
stdin
Standard input is empty
stdout
1.46105