結果

問題 No.75 回数の期待値の問題
ユーザー masamasa
提出日時 2015-02-18 23:46:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,437 ms / 5,000 ms
コード長 577 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 71,392 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 02:19:08
合計ジャッジ時間 70,239 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,382 ms
4,380 KB
testcase_01 AC 3,437 ms
4,380 KB
testcase_02 AC 3,382 ms
4,380 KB
testcase_03 AC 3,228 ms
4,376 KB
testcase_04 AC 3,389 ms
4,380 KB
testcase_05 AC 3,389 ms
4,380 KB
testcase_06 AC 3,387 ms
4,376 KB
testcase_07 AC 3,239 ms
4,376 KB
testcase_08 AC 3,221 ms
4,380 KB
testcase_09 AC 3,190 ms
4,376 KB
testcase_10 AC 3,192 ms
4,376 KB
testcase_11 AC 3,170 ms
4,380 KB
testcase_12 AC 3,161 ms
4,380 KB
testcase_13 AC 3,140 ms
4,380 KB
testcase_14 AC 3,143 ms
4,380 KB
testcase_15 AC 3,101 ms
4,380 KB
testcase_16 AC 3,039 ms
4,380 KB
testcase_17 AC 3,086 ms
4,376 KB
testcase_18 AC 3,032 ms
4,376 KB
testcase_19 AC 3,030 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <random>

using namespace std;

const int MAX_ROLL = 1e8;

int main() {
	int k;
	cin >> k;

	int seed = 0;
	mt19937 mt(seed);
	uniform_int_distribution<> dice(1, 6);


	int sum = 0;
	int start = 0;
	long long success = 0;
	for (int i = 0; i < MAX_ROLL; i++) {
		sum += dice(mt);

		if (sum == k) {
			success++;
			sum = 0;
		} else if (sum > k) {
			sum = 0;
		}
	}

	double ans = success != 0 ? 1.0 * MAX_ROLL / success : MAX_ROLL;
	printf("%.6f\n", ans);

	return 0;
}
0