結果

問題 No.173 カードゲーム(Medium)
ユーザー pekempeypekempey
提出日時 2015-08-17 20:32:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 188 ms / 3,000 ms
コード長 1,547 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 150,240 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 12:37:26
合計ジャッジ時間 3,018 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,384 KB
testcase_01 AC 23 ms
4,380 KB
testcase_02 AC 154 ms
4,380 KB
testcase_03 AC 153 ms
4,376 KB
testcase_04 AC 149 ms
4,376 KB
testcase_05 AC 127 ms
4,376 KB
testcase_06 AC 97 ms
4,380 KB
testcase_07 AC 88 ms
4,380 KB
testcase_08 AC 87 ms
4,384 KB
testcase_09 AC 188 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

struct XorShift {
	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);
	}
};

bool usedA[10], usedB[10];

int main() {
	int N;
	double PA, PB;
	cin >> N >> PA >> PB;
	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 winA = 0;
	int winB = 0;

	XorShift random;
	const int C = 2e5;
	rep (ii, C) {
		int a = 0;
		int b = 0;
		vector<int> X(A), Y(B);

		rep (i, N) {
			int ia, ib;
			if (i == N - 1 || random.nextDouble() <= PA) {
				ia = 0;
			} else {
				ia = random.nextInt(1, X.size() - 1);
			}

			if (i == N - 1 || random.nextDouble() <= PB) {
				ib = 0;
			} else {
				ib = random.nextInt(1, Y.size() - 1);
			}

			if (X[ia] > Y[ib]) {
				a += X[ia] + Y[ib];
			} else {
				b += X[ia] + Y[ib];
			}

			X.erase(X.begin() + ia);
			Y.erase(Y.begin() + ib);
		}

		if (a > b) winA++;
		if (a < b) winB++;
	}

	double ans = (double)winA / C;
	printf("%.20f\n", ans);
}
0