어제 심심해서 생일문제 모의실험 코드를 만들어봤는데.. 뭔가 좀이상해요 ㅠㅠ

조회수 567회
#include <iostream>
#include <cstdlib>
#include <random>

#include "pch.h"

using namespace std;


typedef unsigned long long ULL;

void Create_Random_Number(ULL arr[], int Array_Size, int min = 1, int max = 365) {

    int idx;
    random_device rd;
    mt19937_64 rnd(rd());

    uniform_int_distribution<int> rn(min, max);

    for (idx = 0; idx < Array_Size; idx++) {

        arr[rn(rnd)]++;
    }
}

bool Overlap_Check(ULL arr[]) {

    int cnt, TEMP = 0;
    int idx = 0;

    for (cnt = 0; cnt < 365; cnt++) {

        if (arr[cnt] > 1) {

            idx++;
        }
    }

    cout << TEMP << endl;

    return idx > 0 ? true : false;
}

int main(int argc, char const *argv[]) {

    while (true) {

        int idx, cnt;
        int cnt_TEMP;
        int Ovl_cnt = 0;

        cout << "인원수 반복횟수" << endl;
        cin >> idx >> cnt;

        if (idx == 0 || cnt == 0) {

            return EXIT_SUCCESS;
        }

        cout << endl;

        for (cnt_TEMP = 0; cnt_TEMP < cnt; cnt_TEMP++) {

            ULL arr[366];

            Create_Random_Number(arr, idx);

            if (Overlap_Check(arr) == true) {

                Ovl_cnt++;
            }
        }

        cout << "총 중복 횟수" << Ovl_cnt << endl;
        cout << "총 중복 확률" << ((double)Ovl_cnt / (double)cnt) * 100 << "%" << endl;
    }

    return EXIT_SUCCESS;
}
총 중복 횟수 = 1000
총 충돌 확률 = 100%

이렇게 결과가 나오네요.. 대충 cout 추가하면서 테스트 해 본 결과 Overlap_Check 함수에서 뭔가 문제가 나온것 같은데 ㅠㅠ 뭔지를 모르겠어요.

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)