結果
| 問題 | No.173 カードゲーム(Medium) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-31 16:02:10 |
| 言語 | D (dmd 2.111.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,528 bytes |
| 記録 | |
| コンパイル時間 | 5,140 ms |
| コンパイル使用メモリ | 222,156 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-12-31 16:02:23 |
| 合計ジャッジ時間 | 12,259 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 1 |
ソースコード
module main;
// https://mayokoex.hatenablog.com/entry/2015/03/27/142127 より
// モンテカルロ法
import std;
alias P = Tuple!(int, int);
immutable repeatCount = 10_000;
int N;
int[] A, B;
uint PA, PB;
bool win()
{
int aPoint = 0, bPoint = 0;
auto aRest = [true].replicate(N), bRest = [true].replicate(N);
foreach (i; 0 .. N - 1) {
P[] a, b;
foreach (j; 0 .. N) {
if (aRest[j]) a ~= P(A[j], j);
if (bRest[j]) b ~= P(B[j], j);
}
a.sort;
b.sort;
int aCard, bCard;
if (uniform!"[]"(0, 1000) <= PA) {
aCard = a[0][0];
aRest[a[0][1]] = false;
} else {
int tmp = uniform!"[]"(1, N - i - 1);
aCard = a[tmp][0];
aRest[a[tmp][1]] = false;
}
if (uniform!"[]"(0, 1000) <= PB) {
bCard = b[0][0];
bRest[b[0][1]] = false;
} else {
int tmp = uniform!"[]"(1, N - i - 1);
bCard = b[tmp][0];
bRest[b[tmp][1]] = false;
}
if (aCard > bCard) aPoint += aCard + bCard;
else bPoint += aCard + bCard;
}
int a, b;
foreach (i; 0 .. N) {
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;
}
void main()
{
// 入力
double[2] P;
readln.chomp.formattedRead("%d %f %f", N, P[0], P[1]);
PA = round(P[0] * 1000).to!uint;
PB = round(P[1] * 1000).to!uint;
A = readln.split.to!(int[]);
B = readln.split.to!(int[]);
// 答えの計算
int winNum = 0;
foreach (_; 0 .. repeatCount) {
winNum += win();
}
double ans = winNum;
ans /= repeatCount;
// 答えの出力
writefln("%.10f", ans);
}