結果
問題 | No.173 カードゲーム(Medium) |
ユーザー | fumofumofuni |
提出日時 | 2021-01-22 01:37:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 905 ms / 3,000 ms |
コード長 | 2,382 bytes |
コンパイル時間 | 2,041 ms |
コンパイル使用メモリ | 203,824 KB |
最終ジャッジ日時 | 2025-01-18 03:14:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=(n)-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define rev(x) reverse(x); using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={-1,0,1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } ll p,q; random_device rnd; // 非決定的な乱数生成器を生成 mt19937 mt(rnd()); // メルセンヌ・ツイスタの32ビット版、引数は初期シード値 uniform_int_distribution<> rand1(1,1000); ll point(set<ll> &a,set<ll> &b){ if(a.size()==1)return (*a.begin()>*b.begin()? *a.begin()+*b.begin():0); ll ret=0; ll x,y; if(rand1(mt)<=p)x=*a.begin(); else { uniform_int_distribution<> rand2(1,a.size()-1); ll k=rand2(mt); auto itr=a.begin();rep(i,k)itr++; x=*itr; } if(rand1(mt)<=q)y=*b.begin(); else { uniform_int_distribution<> rand2(1,b.size()-1); ll k=rand2(mt);//cout << k <<endl; auto itr=b.begin();rep(i,k)itr++; y=*itr; } //cout << x <<" " << y <<endl; a.erase(x);b.erase(y); return (x>y? x+y+point(a,b):point(a,b)); } int main(){ ll n;cin >> n; string pp,qq;cin >> pp >> qq; p=stoll(pp.substr(2)),q=stoll(qq.substr(2)); set<ll> a,b; ll al=0; rep(i,n){ ll x;cin >> x;a.ins(x);al+=x; } rep(i,n){ ll x;cin >> x;b.ins(x);al+=x; } double win=0,match=0; while(true){ set<ll> aa=a,bb=b; ll k=point(aa,bb); //cout << k <<endl; if(k>al-k)win++; match++; if(match>=200000)break; } CST(10); cout << win/match <<endl; }