結果

問題 No.58 イカサマなサイコロ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2018-03-25 18:50:30
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 742 ms / 5,000 ms
コード長 1,068 bytes
コンパイル時間 1,002 ms
コンパイル使用メモリ 137,940 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-07 17:33:46
合計ジャッジ時間 5,509 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
5,248 KB
testcase_01 AC 742 ms
5,376 KB
testcase_02 AC 142 ms
5,376 KB
testcase_03 AC 80 ms
5,376 KB
testcase_04 AC 418 ms
5,376 KB
testcase_05 AC 495 ms
5,376 KB
testcase_06 AC 633 ms
5,376 KB
testcase_07 AC 150 ms
5,376 KB
testcase_08 AC 287 ms
5,376 KB
testcase_09 AC 694 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iomanip>
#include <iostream>
#include <random>


constexpr unsigned int EXP = 5000000;
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<unsigned short> dice(1, 6);
std::uniform_int_distribution<unsigned short> unfair_dice(4, 6);


unsigned short experiment(unsigned short& n, unsigned short& k) {
	unsigned short taro_score = 0;
	unsigned short jiro_score = 0;
	for (unsigned short i = 0; i < n; i++) {
		jiro_score += dice(mt);
		if (i < k) {
			taro_score += unfair_dice(mt);
		} else {
			taro_score += dice(mt);
		}
	}
	if (taro_score > jiro_score) {
		return 1;
	} else {
		return 0;
	}
}


double compute_probability(unsigned short n, unsigned short k, unsigned int times) {
	unsigned int taro_wins = 0;
	for (unsigned int i = 0; i < times; i++) {
		taro_wins += experiment(n, k);
	}
	return (double)taro_wins / (double)times;
}


int main()
{
	unsigned short n, k;
	std::cin >> n >> k;
	double answer = compute_probability(n, k, EXP);
	std::cout << std::fixed << std::setprecision(6) << answer << std::endl;
    return 0;
}
0