結果

問題 No.58 イカサマなサイコロ
コンテスト
ユーザー はむ吉🐹
提出日時 2016-02-19 20:32:53
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 107 ms / 5,000 ms
コード長 1,068 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 738 ms
コンパイル使用メモリ 101,708 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-10 18:20:35
合計ジャッジ時間 1,946 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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