結果

問題 No.173 カードゲーム(Medium)
ユーザー codershifthcodershifth
提出日時 2016-01-20 20:44:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 617 ms / 3,000 ms
コード長 2,034 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 167,872 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 13:36:47
合計ジャッジ時間 6,566 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,348 KB
testcase_01 AC 50 ms
4,348 KB
testcase_02 AC 560 ms
4,348 KB
testcase_03 AC 552 ms
4,348 KB
testcase_04 AC 551 ms
4,348 KB
testcase_05 AC 497 ms
4,348 KB
testcase_06 AC 458 ms
4,348 KB
testcase_07 AC 437 ms
4,348 KB
testcase_08 AC 435 ms
4,348 KB
testcase_09 AC 617 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];


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

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

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

            REP(i,N)
            {
                int ia,ib;

                ia = ib = 0;
                if (a.size() > 1)
                {
                    sort(RANGE(a));
                    sort(RANGE(b));
                    double u = g(engine);
                    if ( u >= Pa )
                    {// 最小値以外のカードを当確率で選ぶ
                        int x = (u-Pa)/(1.0-Pa)*(a.size()-1);
                        ia = x+1;
                    }
                    u = g(engine);
                    if ( u >= Pb )
                    {
                        int x = (u-Pb)/(1.0-Pb)*(b.size()-1);
                        ib = x+1;
                    }
                }

                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;
        }
        p /= T;

        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