結果

問題 No.425 ジャンケンの必勝法
ユーザー te-shte-sh
提出日時 2017-10-27 16:44:31
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 151,016 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 16:30:53
合計ジャッジ時間 3,763 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,376 KB
testcase_01 AC 5 ms
4,376 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void main()
{
  auto rd = readln.split.to!(int[]), p = rd[0], q = rd[1];

  auto n = 101, a = new real[][](n, n+1);
  auto r2 = real(1)/2, r3 = real(1)/3;

  foreach (i; 0..n) {
    a[i][] = 0;
    a[i][i] = 1;
    a[i][max(i-q, 0)] -= r2 * i / 100;
    a[i][min(i+q, 100)] -= r3 * (100 - i) / 100;
    a[i][n] = (r2 * i + r3 * (100 - i)) / 100;
  }

  gaussElimination(a, n);

  writefln("%.7f", (a[p][n] + 1) * r3);
}

auto gaussElimination(T)(ref T[][] a, size_t n)
{
  import std.math;

  size_t p;
  T pmax;

  foreach (k; 0..n-1) {
    p = k;
    pmax = a[k][k].abs;

    foreach (i; k+1..n)
      if (a[i][k].abs > pmax) {
        p = i;
        pmax = a[i][k].abs;
      }

    if (p != k) swap(a[k], a[p]);

    auto akk = a[k][k];
    foreach (i; k+1..n) {
      auto aik = a[i][k];
      foreach (j; k..n+1)
        a[i][j] -= aik * (a[k][j] / akk);
    }
  }

  a[n-1][n] /= a[n-1][n-1];
  foreach_reverse (i; 0..n-1) {
    auto ax = T(0);
    foreach (j; i+1..n)
      ax += a[i][j] * a[j][n];
    a[i][n] = (a[i][n] - ax) / a[i][i];
  }
}
0