結果

問題 No.58 イカサマなサイコロ
ユーザー llllll
提出日時 2018-04-25 06:09:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 5,000 ms
コード長 1,037 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 106,856 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 05:21:10
合計ジャッジ時間 2,825 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
4,376 KB
testcase_01 AC 202 ms
4,384 KB
testcase_02 AC 47 ms
4,376 KB
testcase_03 AC 31 ms
4,380 KB
testcase_04 AC 123 ms
4,376 KB
testcase_05 AC 141 ms
4,376 KB
testcase_06 AC 182 ms
4,376 KB
testcase_07 AC 52 ms
4,380 KB
testcase_08 AC 89 ms
4,376 KB
testcase_09 AC 177 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

int N, K;

bool trial(mt19937 &mt) {
    int taro = 0;
    int jiro = 0;

    for (int i = 0; i < K; i++) {
        taro += mt() % 3 + 4;
        jiro += mt() % 6 + 1;
    }

    for (int i = 0; i < N - K; i++) {
        taro += mt() % 6 + 1;
        jiro += mt() % 6 + 1;
    }

    return taro > jiro;
}

double monte(mt19937 &mt) {
    int win = 0;
    int lose = 0;
    for (int i = 0; i < 1000000; i++) {
        if (trial(mt)) {
            win++;
        } else {
            lose++;
        }
    }

    return (win * 1.0 / (win + lose));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    random_device rnd;
    mt19937 mt(rnd());

    cin >> N >> K;

    cout << monte(mt) << endl;

    return 0;
}
0