結果

問題 No.173 カードゲーム(Medium)
ユーザー koyumeishikoyumeishi
提出日時 2015-03-27 00:45:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 192 ms / 3,000 ms
コード長 1,750 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 80,376 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-11 10:35:57
合計ジャッジ時間 2,486 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,380 KB
testcase_01 AC 27 ms
4,384 KB
testcase_02 AC 152 ms
4,384 KB
testcase_03 AC 150 ms
4,384 KB
testcase_04 AC 147 ms
4,384 KB
testcase_05 AC 124 ms
4,380 KB
testcase_06 AC 102 ms
4,388 KB
testcase_07 AC 91 ms
4,384 KB
testcase_08 AC 91 ms
4,380 KB
testcase_09 AC 192 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0