結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-13 11:49:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 395 ms / 3,000 ms |
| コード長 | 1,335 bytes |
| コンパイル時間 | 601 ms |
| コンパイル使用メモリ | 64,800 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-30 00:45:03 |
| 合計ジャッジ時間 | 3,475 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
int choice(double p, int n, int bit) {
int r = __builtin_popcount(bit);
int cnt = 0;
if (r == 1) {
cnt = 0;
} else {
if (rand() % 1000 < p * 1000 - 0.5) {
cnt = 0;
} else {
cnt = 1 + (rand() % (r - 1));
}
}
REP(i, 0, n) {
if (bit & 1 << i) {
if (cnt == 0) { return i; }
cnt--;
}
}
assert (0);
}
int main(void){
int n;
double p1, p2;
cin >> n >> p1 >> p2;
VI a(n), b(n);
int tot_sc = 0;
REP(i, 0, n) {
cin >> a[i];
tot_sc += a[i];
}
REP(i, 0, n) {
cin >> b[i];
tot_sc += b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
double tot = 0;
int num_iteration = 160000;
REP(iteration, 0, num_iteration) {
int sc = 0;
int bita = (1 << n) - 1;
int bitb = bita;
REP(i, 0, n) {
int ca = choice(p1, n, bita);
int cb = choice(p2, n, bitb);
bita ^= 1 << ca;
bitb ^= 1 << cb;
if (a[ca] > b[cb]) {
sc += a[ca] + b[cb];
}
}
assert (bita == 0);
assert (bitb == 0);
if (sc * 2 > tot_sc) {
tot += 1;
}
}
printf("%.15f\n", tot / num_iteration);
}