結果

問題 No.173 カードゲーム(Medium)
ユーザー mamekinmamekin
提出日時 2015-04-05 17:07:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,352 ms / 3,000 ms
コード長 1,761 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 95,668 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 04:35:29
合計ジャッジ時間 15,871 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
4,376 KB
testcase_01 AC 155 ms
4,384 KB
testcase_02 AC 2,019 ms
4,376 KB
testcase_03 AC 2,008 ms
4,380 KB
testcase_04 AC 1,981 ms
4,380 KB
testcase_05 AC 1,706 ms
4,376 KB
testcase_06 AC 1,416 ms
4,380 KB
testcase_07 AC 1,291 ms
4,376 KB
testcase_08 AC 1,256 ms
4,376 KB
testcase_09 AC 2,352 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

unsigned xor128(){
    static unsigned x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

int main()
{
    int n;
    double pa, pb;
    cin >> n >> pa >> pb;
    vector<int> a(n), b(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    for(int i=0; i<n; ++i)
        cin >> b[i];

    const int LOOP_TIME = 1000000;
    int win = 0;
    for(int t=0; t<LOOP_TIME; ++t){
        vector<int> x = a;
        vector<int> y = b;

        int score = 0;
        for(int i=0; i<n; ++i){
            sort(x.begin(), x.end() - i);
            sort(y.begin(), y.end() - i);

            if(i < n - 1){
                if(xor128() / (double)UINT_MAX > pa){
                    int j = xor128() % (n - 1 - i) + 1;
                    swap(x[0], x[j]);
                }
                if(xor128() / (double)UINT_MAX > pb){
                    int j = xor128() % (n - 1 - i) + 1;
                    swap(y[0], y[j]);
                }
            }

            if(x[0] > y[0])
                score += x[0] + y[0];
            else if(x[0] < y[0])
                score -= x[0] + y[0];

            swap(x[0], x[n-1-i]);
            swap(y[0], y[n-1-i]);
        }

        if(score > 0)
            ++ win;
    }

    double ans = win / (double)LOOP_TIME;
    printf("%.10f\n", ans);

    return 0;
}
0