結果

問題 No.76 回数の期待値で練習
ユーザー te-sh
提出日時 2016-09-08 17:28:39
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 719 bytes
コンパイル時間 2,615 ms
コンパイル使用メモリ 163,108 KB
実行使用メモリ 18,072 KB
最終ジャッジ日時 2024-06-12 04:14:29
合計ジャッジ時間 2,684 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

const real[] pi = [
  0, 0.08333333333333326, 0.16666666666666674, 0.2500000000000001,
  0.08333333333333298, 0.24999999999999983, 0.16666666666666718
];

void main()
{
  auto t = readln.chomp.to!size_t;
  auto ni = iota(t).map!(_ => readln.chomp.to!int).array;

  auto maxN = ni.reduce!(max);
  auto memo = new real[](maxN + 1);

  foreach (i; 1..maxN + 1) {
    memo[i] = 1;
    foreach (d; 1..6 + 1)
      memo[i] += i - d <= 0 ? 0 : memo[i - d] * pi[d];
  }

  foreach (n; ni)
    writefln("%.6f", memo[n]);
}
0