結果

問題 No.173 カードゲーム(Medium)
ユーザー keikei
提出日時 2018-09-09 01:49:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 398 ms / 3,000 ms
コード長 2,480 bytes
コンパイル時間 1,645 ms
コンパイル使用メモリ 172,872 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 12:46:40
合計ジャッジ時間 4,915 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,376 KB
testcase_01 AC 71 ms
4,376 KB
testcase_02 AC 337 ms
4,380 KB
testcase_03 AC 338 ms
4,380 KB
testcase_04 AC 331 ms
4,380 KB
testcase_05 AC 278 ms
4,376 KB
testcase_06 AC 233 ms
4,380 KB
testcase_07 AC 209 ms
4,376 KB
testcase_08 AC 206 ms
4,376 KB
testcase_09 AC 398 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://yukicoder.me/problems/no/173>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

typedef long double ld;

vector<int> get(vector<int> V,ld P){
    vector<int> ret;
    size_t sz = V.size();
    for(int i = 0; i < sz-1;i++){
        int nowsz = (int)V.size();
        ld p = rand()*1.0/RAND_MAX;
        int x = 0;
        if(p < P) x = 0;
        else x = 1 + (sz-1-i)*(p-P)/(1-P);
        
        ret.push_back(V[x]);
        V.erase(V.begin()+x);
    }
    ret.push_back(*V.begin());
    return ret;
}
ld solve(){
    srand((unsigned int)time(NULL));
    ld res = 0;
    int N; cin >> N;
    ld Pa,Pb; cin >> Pa >> Pb;
    vector<int> A(N),B(N);
    for(auto& in:A) cin >> in;
    for(auto& in:B) cin >> in;
    
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    
    ld win = 0;
    ld sum = 0;
    for(int kassa = 0; kassa < 200000; kassa++){
        auto tA = get(A,Pa),tB = get(B,Pb);
        
        int score = 0;
        for(int i = 0; i < N;i++){
            if(tA[i] > tB[i]) score += tA[i] + tB[i];
            if(tA[i] < tB[i]) score -= tA[i] + tB[i];
        }
        sum+=1;
        if(score>0)win+=1;
    }
    res = win/sum;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12) << solve() << endl;
    return 0;
}
0