結果

問題 No.173 カードゲーム(Medium)
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-31 15:28:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 436 ms / 3,000 ms
コード長 1,214 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 69,616 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 06:44:17
合計ジャッジ時間 4,085 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,376 KB
testcase_01 AC 86 ms
4,376 KB
testcase_02 AC 388 ms
4,376 KB
testcase_03 AC 377 ms
4,376 KB
testcase_04 AC 378 ms
4,380 KB
testcase_05 AC 332 ms
4,376 KB
testcase_06 AC 288 ms
4,376 KB
testcase_07 AC 269 ms
4,380 KB
testcase_08 AC 268 ms
4,380 KB
testcase_09 AC 436 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int n;
double pa, pb;

vector<int> solve(double p){//取り出す順番の添字を返す
	vector<int> v, ret;
	rep(i, n) v.push_back(i);//スロット

	int x;
	rep(i, n - 1){
		//rand()%(B-A+1)+A; B=999 A=500
		// double nowp = (double)(rand() % (500) + 500) / 1000.0;
		double nowp = rand()*1.0/RAND_MAX;
		if(nowp <= p) x = 0;
		else x = 1 + (n - i - 1) * (nowp - p) / (1 - p);
		if(x < 0) x = 0;
		if(n - 1 - i < x) x = n - 1 - i;
		ret.push_back(v[x]);
		v.erase(v.begin() + x);
	}
	ret.push_back(v[0]);//使うカードが一枚しかない場合
	return ret;
}

int main(void){
	cin >> n >> pa >> pb;
	vector<int> a(n), b(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	
	int win = 0;
	rep(i, 200000){
		vector<int> va, vb;
		va = solve(pa);
		vb = solve(pb);
		int sa = 0, sb = 0;
		rep(j, n){
			if(a[va[j]] > b[vb[j]]) sa += a[va[j]] + b[vb[j]];
			else sb += a[va[j]] + b[vb[j]];
		}
		if(sa > sb) win++;
	}
	printf("%.9f\n", (double)win / 200000.0);
	return 0;
}
0