結果

問題 No.173 カードゲーム(Medium)
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-31 16:06:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,164 bytes
コンパイル時間 850 ms
コンパイル使用メモリ 66,936 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 21:37:07
合計ジャッジ時間 8,318 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
5,248 KB
testcase_01 AC 195 ms
5,376 KB
testcase_02 AC 892 ms
5,376 KB
testcase_03 AC 894 ms
5,376 KB
testcase_04 AC 878 ms
5,376 KB
testcase_05 AC 791 ms
5,376 KB
testcase_06 AC 717 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 670 ms
5,376 KB
testcase_09 AC 1,002 ms
5,376 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=1000 A=1
		double nowp = (rand() % (1000) + 1) / 1000.0;
		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, 400000){
		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 / 400000.0);
	return 0;
}
0