fork(2) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int fire ( double chance ) {
  6. int res = rand () % 3;
  7. if ( rand () / double(RAND_MAX) < chance ) {
  8. return res + 1;
  9. }
  10.  
  11. return 0;
  12. }
  13.  
  14. int main() {
  15. double A = 0;
  16. srand ( 12 );
  17. for ( int i = 0; i < 100000; i++ ) {
  18. int one = fire ( 0.6 ),
  19. two = fire ( 0.6 ),
  20. three = fire ( 0.6 );
  21.  
  22. if ( one == two && three != one || one == three && two != one ) {
  23. A++;
  24. }
  25. }
  26.  
  27. cout << A / 100000 << endl;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0.02s 3296KB
stdin
Standard input is empty
stdout
0.38294