結果

問題 No.173 カードゲーム(Medium)
ユーザー 古寺いろは古寺いろは
提出日時 2015-03-26 23:49:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,653 ms / 3,000 ms
コード長 1,515 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 149,304 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 10:25:43
合計ジャッジ時間 9,548 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,376 KB
testcase_01 AC 69 ms
4,376 KB
testcase_02 AC 1,213 ms
4,380 KB
testcase_03 AC 1,218 ms
4,376 KB
testcase_04 AC 1,161 ms
4,376 KB
testcase_05 AC 893 ms
4,376 KB
testcase_06 AC 594 ms
4,376 KB
testcase_07 AC 414 ms
4,376 KB
testcase_08 AC 395 ms
4,376 KB
testcase_09 AC 1,653 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

bool usedA[20];
bool usedB[20];

int MAX = 1000;

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];
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	double count = 0;
	int loop = 400000;
	for (int t = 0; t < loop; t++)
	{
		for (int i = 0; i < N; i++)
		{
			usedA[i] = usedB[i] = false;
		}
		int score = 0;
		for (int i = 0; i < N; i++)
		{
			int chooseA = 0;
			double p = PA;
			double p2 = 0;
			double nokori = 1;
			if (i == N - 1) p = 1;
			else p2 = (1 - PA) / (N - 1 - i);
			for (int j = 0; j < N; j++)
			{
				if (usedA[j]) continue;
				chooseA = j;
				if ((rand() % MAX) / (double)MAX < p / nokori){
					break;
				}
				nokori -= p;
				p = p2;
			}

			int chooseB = 0;
			p = PB;
			p2 = 0;
			nokori = 1;
			if (i == N - 1) p = 1;
			else p2 = (1 - PB) / (N - 1 - i);
			for (int j = 0; j < N; j++)
			{
				if (usedB[j]) continue;
				chooseB = j;
				if ((rand() % MAX) / (double)MAX < p / nokori){
					break;
				}
				nokori -= p;
				p = p2;
			}
			//cout << chooseA << " " << chooseB << " " << (rand()%MAX) << endl;
			//cin >> score;
			if (A[chooseA] > B[chooseB]) score += A[chooseA] + B[chooseB];
			if (A[chooseA] < B[chooseB]) score -= A[chooseA] + B[chooseB];
			usedA[chooseA] = usedB[chooseB] = true;
		}
		if (score > 0) count += 1;
	}
	printf("%.14f", count / loop);
	cin >> count;
}

0