結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
nsd_fb
|
| 提出日時 | 2015-03-27 00:18:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2,802 ms / 3,000 ms |
| コード長 | 2,046 bytes |
| コンパイル時間 | 1,582 ms |
| コンパイル使用メモリ | 165,180 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-29 01:15:55 |
| 合計ジャッジ時間 | 32,830 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
#include <sys/time.h>
#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
#define REP(i, a, b) for(int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
unsigned seed128[4];
inline void seed(unsigned s){
for(int i=1; i<=4; i++) {
seed128[i-1] = s = 1812433253U * (s^(s>>30)) + i;
}
}
inline unsigned xor_shift() {
unsigned t;
t=(seed128[0]^(seed128[0]<<11));
seed128[0]=seed128[1];
seed128[1]=seed128[2];
seed128[2]=seed128[3];
return seed128[3]=(seed128[3]^(seed128[3]>>19))^(t^(t>>8));
}
constexpr double LIMIT = 3.0;
int n;
double pa, pb;
vector<int> a, b;
inline double sec() {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + tv.tv_usec * 1e-6;
}
inline int choice(double p, vector<int> &card) {
int idx = -1;
if(card.size() == 1 || (double)xor_shift() / UINT_MAX < p) {
idx = 0;
}
else {
idx = xor_shift() % (card.size() - 1) + 1;
}
const int res = card[idx];
card.erase(begin(card) + idx);
//swap(card[idx], card.back());
//card.pop_back();
return res;
}
inline int simulate() {
int score_a = 0, score_b = 0;
vector<int> card_a(a), card_b(b);
for(int i = 0; i < n; ++i) {
const int ca = choice(pa, card_a);
const int cb = choice(pb, card_b);
if(ca > cb) {
score_a += ca + cb;
}
else {
score_b += ca + cb;
}
}
return score_a > score_b;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(10);
const auto start = sec();
seed(1940401);
cin >> n >> pa >> pb;
a.resize(n);
b.resize(n);
for(auto &e : a) cin >> e;
for(auto &e : b) cin >> e;
sort(begin(a), end(a));
sort(begin(b), end(b));
int win = 0;
int cnt = 0;
while(sec() - start < LIMIT - 0.2) {
win += simulate();
++cnt;
}
cout << (double)win / cnt << endl;
return EXIT_SUCCESS;
}
nsd_fb