572496 ランダム
 HOME | DIARY | PROFILE 【フォローする】 【ログイン】

t-cross Private Research Institute (tPRI)

t-cross Private Research Institute (tPRI)

【毎日開催】
15記事にいいね!で1ポイント
10秒滞在
いいね! --/--
おめでとうございます!
ミッションを達成しました。
※「ポイントを獲得する」ボタンを押すと広告が表示されます。
x

PR

Calendar

Profile

t-cross

t-cross

Category

Archives

2024.07
2024.06
2024.05
2024.04
2024.03
2017.06.17
XML
カテゴリ:IT
#include <iostream>
#include <random>
using namespace std;
int main(){
const int nst  = 40; // 1クラスの人数
const int nrep = 100000; // 繰り返し回数
const int nday = 365; // 1年の日数
int hit[nday];
int count;
random_device rdev; // ランダムシード
mt19937 engine(rdev()); // MT法乱数生成器にランダムシードを設定
uniform_int_distribution<> dist(0, nday-1); // 一様整数乱数発生器
count = 0;
for (int kk = 0; kk < nrep; kk++) {
// 初期化
for (int ii = 0; ii < nday; ii++) {
hit[ii] = 0;
}
// 1クラス分の誕生日データ作成
for (int ii = 0; ii < nst; ii++) {
int select = dist(engine);
hit[select]++;
}
// ワンペアチェック
for (int ii = 0; ii < nday; ii++) {
if (hit[ii] >= 2) {
count++;
break;
}
}
}
 
// 結果出力
double pc = 100.0 * double(count) / double(nrep);
cout << pc << " %" << "  (" << count << "/" << nrep << ")" << endl;
    return 0;
}





お気に入りの記事を「いいね!」で応援しよう

Last updated  2017.06.17 12:54:00



© Rakuten Group, Inc.