結果

問題 No.75 回数の期待値の問題
ユーザー te-shte-sh
提出日時 2017-01-25 15:59:13
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 659 bytes
コンパイル時間 1,968 ms
コンパイル使用メモリ 150,188 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 00:50:41
合計ジャッジ時間 3,088 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

void main()
{
  auto k = readln.chomp.to!int;

  auto eps = real(0.001);

  auto lower(real _, real a) {
    return calcE0(k, a) < a;
  }

  auto r = real(1);
  while (!lower(0, r))
    r *= 2;

  auto m = iota(r / 2, r, eps).assumeSorted!lower.upperBound(0);
  writeln(m.front);
}

auto calcE0(int k, real m)
{
  auto ei = new real[](k);
  foreach_reverse (i; k.iota) {
    ei[i] = 0;
    foreach (j; 1..7) {
      if (i + j > k)
        ei[i] += m;
      else if (i + j == k)
        ei[i] += 0;
      else
        ei[i] += ei[i + j];
    }
    ei[i] = ei[i] / 6 + 1;
  }
  return ei[0];
}
0