結果

問題 No.173 カードゲーム(Medium)
ユーザー kimiyukikimiyuki
提出日時 2016-02-27 12:56:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,922 ms / 3,000 ms
コード長 1,271 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 85,328 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 18:31:34
合計ジャッジ時間 17,332 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
4,348 KB
testcase_01 AC 237 ms
4,348 KB
testcase_02 AC 2,311 ms
4,348 KB
testcase_03 AC 2,301 ms
4,348 KB
testcase_04 AC 2,244 ms
4,348 KB
testcase_05 AC 1,865 ms
4,348 KB
testcase_06 AC 1,416 ms
4,348 KB
testcase_07 AC 1,212 ms
4,348 KB
testcase_08 AC 1,201 ms
4,348 KB
testcase_09 AC 2,922 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int choose(double, const std::vector<int>&, std::vector<bool>&, int, Generator&) [with Generator = std::linear_congruential_engine<long unsigned int, 16807, 0, 2147483647>]’:
main.cpp:19:1: warning: control reaches end of non-void function [-Wreturn-type]
   19 | }
      | ^

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <cstdio>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
template <typename Generator>
int choose(double p, vector<int> const & a, vector<bool> & used, int i, Generator & gen) {
    int n = a.size();
    int k = 0;
    if (i != n-1 and uniform_real_distribution<double>()(gen) > p) {
        k = uniform_int_distribution<int>(1,n-i-1)(gen);
    }
    repeat (j,n) if (not used[j]) if (k -- == 0) {
        used[j] = true;
        return a[j];
    }
}
int main() {
    random_device device;
    default_random_engine gen(device());
    int n; double p, q; cin >> n >> p >> q;
    vector<int> a(n); repeat (i,n) cin >> a[i]; sort(a.begin(), a.end());
    vector<int> b(n); repeat (i,n) cin >> b[i]; sort(b.begin(), b.end());
    int win = 0, lose = 0;
    repeat (iteration,1000000) {
        vector<vector<bool> > used(2, vector<bool>(n));
        int score = 0;
        repeat (i,n) {
            int x = choose(p, a, used[0], i, gen);
            int y = choose(q, b, used[1], i, gen);
            score += (x > y ? 1 : -1) * (x + y);
        }
        (score > 0 ? win : lose) += 1;
    }
    printf("%.8lf\n", win /(double) (win + lose));
    return 0;
}
0