結果
| 問題 |
No.65 回数の期待値の練習
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-02-13 21:06:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 896 ms / 5,000 ms |
| コード長 | 661 bytes |
| コンパイル時間 | 753 ms |
| コンパイル使用メモリ | 75,664 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-23 19:51:11 |
| 合計ジャッジ時間 | 12,540 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <random>
using namespace std;
const int max_play = 1e7;
int main() {
int k;
cin >> k;
int seed = 0;
mt19937 mt(seed);
uniform_int_distribution<> dice(1, 6);
vector<int> count(21, 0);
int sum, roll;
int play = 0;
while (play < max_play) {
sum = 0;
roll = 0;
while (sum < k) {
sum += dice(mt);
roll++;
}
count[roll]++;
play++;
}
int total = 0;
for (int i = 0; i < count.size(); i++) {
total += i * count[i];
// cout << count[i] << endl;
}
double ans = 1.0 * total / max_play;
printf("%.6f\n", ans);
return 0;
}