結果

問題 No.173 カードゲーム(Medium)
ユーザー msm1993msm1993
提出日時 2020-10-23 16:03:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 447 ms / 3,000 ms
コード長 1,188 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 91,020 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 15:34:57
合計ジャッジ時間 4,614 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,380 KB
testcase_01 AC 36 ms
4,376 KB
testcase_02 AC 387 ms
4,380 KB
testcase_03 AC 395 ms
4,376 KB
testcase_04 AC 376 ms
4,380 KB
testcase_05 AC 327 ms
4,380 KB
testcase_06 AC 273 ms
4,376 KB
testcase_07 AC 243 ms
4,376 KB
testcase_08 AC 242 ms
4,380 KB
testcase_09 AC 447 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<random>
using namespace std;

uniform_real_distribution<> dist(0.0, 1.0);

int op(double p, set<int> &a, mt19937 &engine){
    int ret;
    if(a.size() == 1 || dist(engine) <= p){
        ret = *a.begin();
        a.erase(a.begin());
    }else{
        uniform_int_distribution<> tmp(1, a.size()-1);
        int pos = tmp(engine);
        auto it = a.begin();
        while(pos--)    it++;
        ret = *it;
        a.erase(it);
    }
    return ret;
}

int main(){
    int n;
    double pa, pb;
    cin >> n >> pa >> pb;
    set<int> ga, gb;
    int x;
    for(int i = 0; i < n; i++)  cin >> x, ga.insert(x);
    for(int i = 0; i < n; i++)  cin >> x, gb.insert(x);

    random_device rd;
    mt19937 engine(rd());

    double win = 0;
    for(int loop = 0; loop < 100000; loop++){
        set<int> a = ga, b = gb;
        int diff = 0;
        for(int i = 0; i < n; i++){
            int aval = op(pa, a, engine);
            int bval = op(pb, b, engine);
            if(aval > bval) diff += aval+bval;
            if(aval < bval) diff -= aval+bval;
        }
        if(diff > 0)    win++;
    }
    cout << win/100000 << endl;
    return 0;
}
0