結果

問題 No.75 回数の期待値の問題
ユーザー diginatudiginatu
提出日時 2014-11-24 00:46:24
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 717 bytes
コンパイル時間 3,532 ms
コンパイル使用メモリ 147,604 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-09-02 19:11:43
合計ジャッジ時間 3,949 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

double solve(int mx) {
  if(mx <= 6) return 1.0/6;
  auto ans = new double[](mx);
  ans.length = mx+2;
  foreach(immutable int x; 1 .. mx+2) {
    if (x == 1) ans[x] = 1;
    else {
      double res = 0;
      foreach(immutable int i; 1 .. 7) {
        res += 1.0/6 * ((x-i>0)?ans[x-i]:0);
      }
      ans[x] = res + 1;
    }
  }
  return ans[mx+1] - ans[mx];
}

void main(){
  auto K = readln().strip().to!int();
  double a = solve(K);
  double ans = 0;
  double a_i=1;
  foreach(immutable int i; 1 .. 10000) {
    ans += i * a * a_i;
    a_i *= 1-a;
  }

  writefln("%1.10f", ans+6);
}
0