結果

問題 No.173 カードゲーム(Medium)
ユーザー nsd_fbnsd_fb
提出日時 2015-03-27 00:18:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,802 ms / 3,000 ms
コード長 2,046 bytes
コンパイル時間 1,531 ms
コンパイル使用メモリ 151,912 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 10:33:07
合計ジャッジ時間 32,762 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,802 ms
4,376 KB
testcase_01 AC 2,801 ms
4,376 KB
testcase_02 AC 2,801 ms
4,376 KB
testcase_03 AC 2,802 ms
4,380 KB
testcase_04 AC 2,801 ms
4,380 KB
testcase_05 AC 2,801 ms
4,380 KB
testcase_06 AC 2,802 ms
4,376 KB
testcase_07 AC 2,801 ms
4,376 KB
testcase_08 AC 2,802 ms
4,376 KB
testcase_09 AC 2,801 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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