結果

問題 No.173 カードゲーム(Medium)
ユーザー fiordfiord
提出日時 2015-08-30 01:05:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,974 ms / 3,000 ms
コード長 806 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 150,308 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 19:46:47
合計ジャッジ時間 22,825 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int n;
double pa,pb;
int tries=0,scs=0;
bool game(vector<int> a,vector<int> b){
	int ap=0,bp=0;
	while(a.size()>0){
		int aa,bb;
		if(rand()%1000<pa*1000||a.size()==1)	aa=0;
		else 	aa=1+rand()%((int)a.size()-1);
		if(rand()%1000<pb*1000||b.size()==1)	bb=0;
		else 	bb=1+rand()%((int)b.size()-1);
		if(a[aa]>b[bb])	ap+=a[aa]+b[bb];
		else 	bp+=a[aa]+b[bb];
		a.erase(a.begin()+aa);	b.erase(b.begin()+bb);
	}
	if(ap>bp)	return true;
	else return false;
}
	
int main(){
	cin>>n>>pa>>pb;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++)	cin>>a[i];
	for(int i=0;i<n;i++)	cin>>b[i];
	sort(a.begin(),a.end());	sort(b.begin(),b.end());
	auto start=time(NULL);
	while(time(NULL)-start<2){
		tries++;
		if(game(a,b))	scs++;
	}
	cout<<(double)scs/tries<<endl;
	return 0;
}
0