結果

問題 No.173 カードゲーム(Medium)
ユーザー ctyl_0ctyl_0
提出日時 2016-01-29 17:42:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 92 ms / 3,000 ms
コード長 2,689 bytes
コンパイル時間 981 ms
コンパイル使用メモリ 91,708 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 16:37:11
合計ジャッジ時間 2,299 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,348 KB
testcase_01 AC 13 ms
4,348 KB
testcase_02 AC 72 ms
4,348 KB
testcase_03 AC 73 ms
4,348 KB
testcase_04 AC 68 ms
4,348 KB
testcase_05 AC 54 ms
4,348 KB
testcase_06 AC 42 ms
4,348 KB
testcase_07 AC 34 ms
4,348 KB
testcase_08 AC 34 ms
4,348 KB
testcase_09 AC 92 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <time.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
// end of template
const double eps = 0.000001;

struct XorShift { // Reference: http://yukicoder.me/submissions/44108
    unsigned z;
    XorShift() : z((unsigned)time(NULL)) {}
    XorShift(int seed) : z(z) {}
    unsigned next() {
        z ^= z << 13;
        z ^= z >> 17;
        z ^= z << 5;
        return z;
    }
    unsigned nextInt(unsigned a, unsigned b) {
        return next() % (b - a + 1) + a;
    }
    double nextDouble() {
        return next() / (double)(1ll << 32);
    }
};

template<typename T>
void rm(vector<T>& v, unsigned int index) // 0: 先頭を削除
{
    v.erase(v.begin() + index);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    XorShift rd;
    int N, a, b;
    cin >> N;
    double pA, pB;
    cin >> pA >> pB;
    pA += eps, pB += eps;
    a = (int)(pA * 1000), b = (int)(pB * 1000);
    vector<int> A_(N), B_(N);
    rep(i, N) cin >> A_[i];
    rep(i, N) cin >> B_[i];
    sort(A_.begin(), A_.end());
    sort(B_.begin(), B_.end());
    
    int wins = 0;
    int rit = 100000;
    rep(i, rit){
        vector<int> A = A_, B = B_;
        int aTot = 0, bTot = 0;
        rep(j, N){
            int aNow, bNow;
            int aSmall = rd.nextInt(1, 1000);
            int bSmall = rd.nextInt(1, 1000);
            if (aSmall <= a || j == N - 1){
                aNow = A[0];
                rm(A, 0);
            }
            else{
                int aLarge = rd.nextInt(1, N - 1 - j);
                aNow = A[aLarge];
                rm(A, aLarge);
            }
            if (bSmall <= b || j == N - 1){
                bNow = B[0];
                rm(B, 0);
            }
            else{
                int bLarge = rd.nextInt(1, N - 1 - j);
                bNow = B[bLarge];
                rm(B, bLarge);
            }
            if (aNow > bNow) aTot += aNow + bNow;
            else bTot += aNow + bNow;
        }
        if (aTot > bTot) {
            wins++;
        }
    }
    
    output(double(wins) / double(rit), 5);
    
    return 0;
}
0