結果

問題 No.173 カードゲーム(Medium)
ユーザー mayoko_mayoko_
提出日時 2015-03-27 14:05:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 153 ms / 3,000 ms
コード長 2,220 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 93,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 01:39:08
合計ジャッジ時間 2,377 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 6 ms
4,380 KB
testcase_02 AC 140 ms
4,376 KB
testcase_03 AC 142 ms
4,380 KB
testcase_04 AC 136 ms
4,380 KB
testcase_05 AC 122 ms
4,380 KB
testcase_06 AC 107 ms
4,380 KB
testcase_07 AC 94 ms
4,376 KB
testcase_08 AC 94 ms
4,376 KB
testcase_09 AC 153 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘bool win()’:
main.cpp:65:12: warning: ‘b’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     int a, b;
            ^
main.cpp:65:9: warning: ‘a’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     int a, b;
         ^

ソースコード

diff #

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <random>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MAXN = 22;
const int SIMULATE_NUM = 10000;
int A[MAXN], B[MAXN];
int N;
unsigned int PA, PB;
random_device rnd;
mt19937 mt(rnd());

bool win() {
    int aPoint = 0, bPoint = 0;
    bool arest[MAXN], brest[MAXN];
    for (int i = 0; i < N; i++) arest[i] = brest[i] = true;
    for (int i = 0; i < N-1; i++) {
        vector<P> a, b;
        for (int j = 0; j < N; j++) {
            if (arest[j]) a.push_back(P(A[j], j));
            if (brest[j]) b.push_back(P(B[j], j));
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        int aCard, bCard;
        if (mt()%1001 <= PA) {
            aCard = a[0].first;
            arest[a[0].second] = false;
        }
        else {
            int rest = N-i-1;
            int tmp = mt()%rest+1;
            aCard = a[tmp].first;
            arest[a[tmp].second] = false;
        }
        if (mt()%1001 <= PB) {
            bCard = b[0].first;
            brest[b[0].second] = false;
        }
        else {
            int rest = N-i-1;
            int tmp = mt()%rest+1;
            bCard = b[tmp].first;
            brest[b[tmp].second] = false;
        }
        if (aCard > bCard) aPoint += aCard+bCard;
        else bPoint += aCard+bCard;
    }
    int a, b;
    for (int i = 0; i < N; i++) {
        if (arest[i]) a = A[i];
        if (brest[i]) b = B[i];
    }
    if (a > b) aPoint += a+b;
    else bPoint += a+b;
    return aPoint > bPoint;
}

int main(void) {
    double pa, pb;
    cin >> N >> pa >> pb;
    PA = pa*1000;
    PB = pb*1000;
    if (1.*PA/1000 < pa) PA++;
    if (1.*PB/1000 < pb) PB++;
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    int num = SIMULATE_NUM;
    int winnum = 0;
    while (num--) {
        if (win()) {
            winnum++;
        }
    }
    printf("%.10lf\n", 1.*winnum/SIMULATE_NUM);
    return 0;
}
0