結果

問題 No.173 カードゲーム(Medium)
ユーザー te-shte-sh
提出日時 2017-02-07 15:56:51
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 370 ms / 3,000 ms
コード長 1,032 bytes
コンパイル時間 2,146 ms
コンパイル使用メモリ 163,120 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 01:23:53
合計ジャッジ時間 5,270 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
4,380 KB
testcase_01 AC 49 ms
4,380 KB
testcase_02 AC 320 ms
4,376 KB
testcase_03 AC 322 ms
4,376 KB
testcase_04 AC 314 ms
4,376 KB
testcase_05 AC 284 ms
4,376 KB
testcase_06 AC 253 ms
4,380 KB
testcase_07 AC 230 ms
4,376 KB
testcase_08 AC 229 ms
4,376 KB
testcase_09 AC 370 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.random;    // random

const auto iter = 100_000;

void main()
{
  auto rd = readln.split, n = rd[0].to!size_t;
  auto pa = (rd[1].to!real * 1000).to!int, pb = (rd[2].to!real * 1000).to!int;
  auto ai = readln.split.to!(int[]);
  auto bi = readln.split.to!(int[]);

  ai.sort(); bi.sort();

  Random rnd;

  auto selectCard(ref int[] ci, int pc) {
    int c;
    if (ci.length == 1 || uniform(0, 1000, rnd) < pc) {
      c = ci.front;
      ci = ci.remove(0);
    } else {
      auto i = uniform(1, ci.length);
      c = ci[i];
      ci = ci.remove(i);
    }
    return c;
  }

  auto calc() {
    auto pta = 0, ptb = 0;
    auto ai2 = ai.dup, bi2 = bi.dup;

    while (!ai2.empty) {
      auto a = selectCard(ai2, pa);
      auto b = selectCard(bi2, pb);
      if (a > b) pta += a + b;
      else if (a < b) ptb += a + b;
    }

    return pta > ptb;
  }

  auto r = 0;
  foreach (_; iter.iota)
    if (calc) ++r;

  writefln("%.3f", r.to!real / iter);
}
0