結果

問題 No.173 カードゲーム(Medium)
ユーザー EmKjpEmKjp
提出日時 2015-03-28 11:11:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 268 ms / 3,000 ms
コード長 1,772 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 83,840 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 10:45:46
合計ジャッジ時間 3,153 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,380 KB
testcase_01 AC 28 ms
4,376 KB
testcase_02 AC 240 ms
4,380 KB
testcase_03 AC 238 ms
4,376 KB
testcase_04 AC 236 ms
4,376 KB
testcase_05 AC 219 ms
4,380 KB
testcase_06 AC 199 ms
4,376 KB
testcase_07 AC 189 ms
4,376 KB
testcase_08 AC 188 ms
4,380 KB
testcase_09 AC 268 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>

using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef vector<int> VI;
typedef vector<VI> VVI;

bool simulation(VI A, VI B, double pa, double pb, int scoreA = 0){
    if(SZ(A) == 0){
        return scoreA > 0;
    }
    int n = SZ(A);
    if(SZ(A) == 1){
        return simulation(VI(), VI(), pa, pb, scoreA + (A[0] > B[0] ? A[0] + B[0] : -(A[0] + B[0])));
    }else{
        bool useMinA = (rand() % 1000) < pa * 1000;
        int targetA = 0;
        if(!useMinA){
            targetA = rand() % (n - 1) + 1;
        }
        bool useMinB = (rand() % 1000) < pb * 1000;
        int targetB = 0;
        if(!useMinB){
            targetB = rand() % (n - 1) + 1;
        }
        int a = A[targetA];
        int b = B[targetB];
        A.erase(A.begin() + targetA);
        B.erase(B.begin() + targetB);
        return simulation(A, B, pa, pb, scoreA + (a > b ? (a+b):-(a+b)));
    }
}

int main()
{
    int N;
    double pa,pb;
    cin>>N>>pa>>pb;
    VI A(N); FOR(i,N) cin>>A[i];
    VI B(N); FOR(i,N) cin>>B[i];
    sort(ALL(A));
    sort(ALL(B));
    double cnt = 0;
    double all = 0 ;
    FOR(_,100000){
        if(simulation(A, B, pa, pb)) {
            cnt++;
        }
        all++;
    }
    printf("%.10f\n", cnt / all);
    return 0;
}
0