結果
問題 | No.173 カードゲーム(Medium) |
ユーザー |
|
提出日時 | 2016-02-27 12:56:20 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2,927 ms / 3,000 ms |
コード長 | 1,271 bytes |
コンパイル時間 | 770 ms |
コンパイル使用メモリ | 85,648 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 11:34:07 |
合計ジャッジ時間 | 17,246 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int choose(double, const std::vector<int>&, std::vector<bool>&, int, Generator&) [with Generator = std::linear_congruential_engine<long unsigned int, 16807, 0, 2147483647>]’: main.cpp:19:1: warning: control reaches end of non-void function [-Wreturn-type] 19 | } | ^
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <random> #include <cstdio> #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) using namespace std; template <typename Generator> int choose(double p, vector<int> const & a, vector<bool> & used, int i, Generator & gen) { int n = a.size(); int k = 0; if (i != n-1 and uniform_real_distribution<double>()(gen) > p) { k = uniform_int_distribution<int>(1,n-i-1)(gen); } repeat (j,n) if (not used[j]) if (k -- == 0) { used[j] = true; return a[j]; } } int main() { random_device device; default_random_engine gen(device()); int n; double p, q; cin >> n >> p >> q; vector<int> a(n); repeat (i,n) cin >> a[i]; sort(a.begin(), a.end()); vector<int> b(n); repeat (i,n) cin >> b[i]; sort(b.begin(), b.end()); int win = 0, lose = 0; repeat (iteration,1000000) { vector<vector<bool> > used(2, vector<bool>(n)); int score = 0; repeat (i,n) { int x = choose(p, a, used[0], i, gen); int y = choose(q, b, used[1], i, gen); score += (x > y ? 1 : -1) * (x + y); } (score > 0 ? win : lose) += 1; } printf("%.8lf\n", win /(double) (win + lose)); return 0; }