結果

問題 No.58 イカサマなサイコロ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-02-19 20:32:53
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,068 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 85,748 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 18:33:56
合計ジャッジ時間 2,788 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 56 ms
4,348 KB
testcase_03 AC 32 ms
4,348 KB
testcase_04 AC 157 ms
4,348 KB
testcase_05 AC 180 ms
4,348 KB
testcase_06 AC 230 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 104 ms
4,348 KB
testcase_09 AC 244 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


constexpr unsigned int EXP = 1000000;
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