結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
EmKjp
|
| 提出日時 | 2015-03-28 11:11:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 239 ms / 3,000 ms |
| コード長 | 1,772 bytes |
| コンパイル時間 | 748 ms |
| コンパイル使用メモリ | 90,416 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-29 01:28:12 |
| 合計ジャッジ時間 | 2,776 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>
using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef vector<int> VI;
typedef vector<VI> VVI;
bool simulation(VI A, VI B, double pa, double pb, int scoreA = 0){
if(SZ(A) == 0){
return scoreA > 0;
}
int n = SZ(A);
if(SZ(A) == 1){
return simulation(VI(), VI(), pa, pb, scoreA + (A[0] > B[0] ? A[0] + B[0] : -(A[0] + B[0])));
}else{
bool useMinA = (rand() % 1000) < pa * 1000;
int targetA = 0;
if(!useMinA){
targetA = rand() % (n - 1) + 1;
}
bool useMinB = (rand() % 1000) < pb * 1000;
int targetB = 0;
if(!useMinB){
targetB = rand() % (n - 1) + 1;
}
int a = A[targetA];
int b = B[targetB];
A.erase(A.begin() + targetA);
B.erase(B.begin() + targetB);
return simulation(A, B, pa, pb, scoreA + (a > b ? (a+b):-(a+b)));
}
}
int main()
{
int N;
double pa,pb;
cin>>N>>pa>>pb;
VI A(N); FOR(i,N) cin>>A[i];
VI B(N); FOR(i,N) cin>>B[i];
sort(ALL(A));
sort(ALL(B));
double cnt = 0;
double all = 0 ;
FOR(_,100000){
if(simulation(A, B, pa, pb)) {
cnt++;
}
all++;
}
printf("%.10f\n", cnt / all);
return 0;
}
EmKjp