結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-03-27 00:45:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 174 ms / 3,000 ms |
| コード長 | 1,750 bytes |
| コンパイル時間 | 710 ms |
| コンパイル使用メモリ | 80,204 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-29 01:18:39 |
| 合計ジャッジ時間 | 2,040 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <ctime>
using namespace std;
class XorShift{
public:
uint32_t x;
uint32_t y;
uint32_t z;
uint32_t w;
XorShift(){
x = 123456789;
y = 362436069;
z = 521288629;
w = 88675123;
}
XorShift(uint32_t seed){
x = 123456789;
y = 362436069;
z = 521288629;
w = seed;
for(int i=0; i<seed%20; i++){
xor128();
}
}
uint32_t xor128(void) {
uint32_t t = x ^ (x << 11);
x = y; y = z; z = w;
return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}
};
XorShift x_rand;
bool win(vector<int>& a, vector<int>& b, int p_a, int p_b, int diff, int rem){
if(rem == 0){
return diff>0;
}
int ca,cb;
if(x_rand.xor128()%1000000 < p_a || rem==1){
ca = a.front();
a.erase(a.begin());
}else{
int index = x_rand.xor128()%(rem-1);
ca = a[1+index];
a.erase(a.begin()+1+index);
}
if(x_rand.xor128()%1000000 < p_b || rem==1){
cb = b.front();
b.erase(b.begin());
}else{
int index = x_rand.xor128()%(rem-1);
cb = b[1+index];
b.erase(b.begin()+1+index);
}
if(ca>cb){
diff += ca+cb;
}else{
diff -= ca+cb;
}
return win(a,b, p_a,p_b, diff, rem-1);
}
int main(){
x_rand = XorShift((unsigned)time(NULL));
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];
}
sort(a.begin(), a.end());
for(int i=0; i<n; i++){
cin >> b[i];
}
sort(b.begin(), b.end());
long long cnt = 0;
int k = 200000;
for(int i=0; i<k; i++){
auto a_ = a;
auto b_ = b;
if(win(a_,b_, pa*1000000, pb*1000000, 0, n)){
cnt++;
}
}
printf("%.6f\n", 1.0*cnt/k);
return 0;
}
koyumeishi