結果

問題 No.173 カードゲーム(Medium)
ユーザー codershifthcodershifth
提出日時 2016-01-20 00:33:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,811 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 165,644 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 13:26:22
合計ジャッジ時間 5,629 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class CardGameMedium {
public:

    void solve(void) {
        int N;
        double Pa,Pb;
        cin>>N>>Pa>>Pb;

        vector<int> A(N);
        vector<int> B(N);

        REP(i,N) cin>>A[i];
        REP(i,N) cin>>B[i];

        double p = 0.0;
        int    n = 0;

        std::mt19937 engine;
        uniform_real_distribution<double> g(0,1);
        const int T = 200000;

        // O(T*N^2)
        REP(_,T)
        {
            int scoreA = 0;
            int scoreB = 0;

            auto a(A);
            auto b(B);

            REP(i,N)
            {
                int ia,ib;
                uniform_int_distribution<int> f(0,a.size()-1);
                double u = g(engine);

                if ( u <= Pa )
                    ia = min_element(RANGE(a))-a.begin();
                else
                    ia = f(engine);

                if ( u <= Pb )
                    ib = min_element(RANGE(b))-b.begin();
                else
                    ib = f(engine);

                if (a[ia] > b[ib])
                    scoreA += a[ia]+b[ib];
                else if (a[ia] < b[ib])
                    scoreB += a[ia]+b[ib];

                a.erase(a.begin()+ia);
                b.erase(b.begin()+ib);
            }
            if (scoreA > scoreB)
                p += 1;
            ++n;
        }
        p /= n;

        cout<<setprecision(20)<<p<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new CardGameMedium();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0