結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
mayoko_
|
| 提出日時 | 2015-03-27 14:05:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,220 bytes |
| コンパイル時間 | 860 ms |
| コンパイル使用メモリ | 95,532 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-03 23:49:13 |
| 合計ジャッジ時間 | 2,493 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 3 |
コンパイルメッセージ
main.cpp: In function ‘bool win()’:
main.cpp:70:27: warning: ‘b’ may be used uninitialized in this function [-Wmaybe-uninitialized]
70 | if (a > b) aPoint += a+b;
| ~^~
main.cpp:70:27: warning: ‘a’ may be used uninitialized in this function [-Wmaybe-uninitialized]
ソースコード
#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;
}
mayoko_