fork download
  1. /* original code written by CyberPunk666 @ipon */
  2.  
  3. #include <iostream>
  4. #include <stdio.h>
  5.  
  6. #include <cstdlib>
  7. #include <ctime>
  8.  
  9. using namespace std;
  10.  
  11. const int N = 1000000;
  12.  
  13.  
  14. int main()
  15. {
  16. bool doors[3];
  17.  
  18. int count_switch = 0;
  19. int count_switch_WIN = 0;
  20.  
  21. int count_NOswitch = 0;
  22. int count_NOswitch_WIN = 0;
  23.  
  24. srand(time(0));
  25.  
  26.  
  27. for (int i = 0; i < N; ++i)
  28. {
  29. for (int j = 0; j < 3; doors[j++] = false);
  30. doors[rand() % 3] = true;
  31.  
  32. int myDoor = rand() % 3;
  33.  
  34. int firstOpen;
  35. do
  36. {
  37. firstOpen = rand() % 3;
  38. } while (firstOpen == myDoor /*|| doors[firstOpen] == true*/);
  39.  
  40. /*mod starts*/
  41. if (doors[firstOpen] == true) continue;
  42. /*mod ends*/
  43.  
  44. int switchDoor = rand() % 2;
  45.  
  46. if (switchDoor == 1)
  47. {
  48. for (int j = 0; j < 3; ++j)
  49. {
  50. if (j != myDoor && j != firstOpen)
  51. {
  52. myDoor = j;
  53. break;
  54. }
  55. }
  56. }
  57.  
  58. if (switchDoor == 1)
  59. {
  60. ++count_switch;
  61. if (doors[myDoor] == true) ++count_switch_WIN;
  62. }
  63. if (switchDoor == 0)
  64. {
  65. ++count_NOswitch;
  66. if (doors[myDoor] == true) ++count_NOswitch_WIN;
  67. }
  68. }
  69.  
  70. double winrate = (double)count_switch_WIN / count_switch * 100;
  71. double winrateNO = (double)count_NOswitch_WIN / count_NOswitch * 100;
  72.  
  73. printf("Switch_WINRATE: %f% (%d game)\nNOSwitch_WINRATE: %f% (%d game)\n", winrate, count_switch, winrateNO, count_NOswitch);
  74.  
  75.  
  76. return 0;
  77. }
  78.  
Success #stdin #stdout 0.12s 3140KB
stdin
Standard input is empty
stdout
Switch_WINRATE:   49.972533% (333133 game)
NOSwitch_WINRATE: 49.957054% (334139 game)