티스토리 뷰

프로그래밍/C++

[C++] 몬티홀 딜레마 문제

AshelCloud 2017. 10. 23. 15:28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<ctime>
 
using namespace std;
 
int main()
{
    int count = 0;
    srand((unsigned int)time(nullptr));
    
    for(int n = 0; n < 10000; n ++)
    {
        vector<int> choices = {001};
        random_shuffle(choices.begin(), choices.end());
        
        int choice = rand() % 3;
 
        for(int i = 0; i < 3; i ++)
        {
            if(i == choice)
            {
                continue;
            }
 
            if(choices[i] == 0)
            {
                choices.erase(choices.begin() + i);
                break;
            }
        }
 
        choice = 1 - min(choice, 1);
        count += choices[choice];
    }
 
    cout << count << endl;
    system("pause");
 
    return 0;
}
cs



친구랑 몬티홀 딜레마 문제에 대해서 어느게 확률이 더 높냐로 2시간싸우다가 코드로 증명했습니다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함