結果

問題 No.65 回数の期待値の練習
ユーザー masamasa
提出日時 2015-02-13 21:06:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,909 ms / 5,000 ms
コード長 661 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 74,024 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 00:45:34
合計ジャッジ時間 23,789 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 288 ms
4,380 KB
testcase_01 AC 353 ms
4,376 KB
testcase_02 AC 452 ms
4,376 KB
testcase_03 AC 805 ms
4,376 KB
testcase_04 AC 539 ms
4,376 KB
testcase_05 AC 604 ms
4,380 KB
testcase_06 AC 711 ms
4,380 KB
testcase_07 AC 908 ms
4,376 KB
testcase_08 AC 960 ms
4,380 KB
testcase_09 AC 1,077 ms
4,380 KB
testcase_10 AC 1,146 ms
4,384 KB
testcase_11 AC 1,260 ms
4,380 KB
testcase_12 AC 1,324 ms
4,376 KB
testcase_13 AC 1,392 ms
4,380 KB
testcase_14 AC 1,442 ms
4,376 KB
testcase_15 AC 1,557 ms
4,376 KB
testcase_16 AC 1,632 ms
4,376 KB
testcase_17 AC 1,733 ms
4,380 KB
testcase_18 AC 1,831 ms
4,380 KB
testcase_19 AC 1,909 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0