結果

問題 No.76 回数の期待値で練習
ユーザー kk
提出日時 2021-03-03 16:18:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 911 bytes
コンパイル時間 2,296 ms
コンパイル使用メモリ 197,664 KB
実行使用メモリ 11,424 KB
最終ジャッジ日時 2024-04-14 08:35:32
合計ジャッジ時間 3,052 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
11,424 KB
testcase_01 AC 17 ms
11,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

vector<double> init() {
  vector<double> e = {
    0.0,
    1.0000000000000000,
    1.0833333333333333,
    1.2569444444444444,
    1.5353009259259260,
    1.6915991512345676,
    2.0513639724794235
  };

  vector<double> ps(7);
  for (int i = 2; i <= 6; i++) {
    double t = e[i] - 1;
    for (int j = i-1; j > 1; j--)
      t -= ps[i-j] * e[j];
    ps[i-1] = t / e[1];
  }

  ps[6] = 1.0;
  for (int i = 1; i <= 5; i++)
    ps[6] -= ps[i];

  return ps;
}


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  auto ps = init();
  vector<double> dp(1000000+1);
  for (int i = 1; i <= 1000000; i++) {
    dp[i] = 1;
    for (int j = 1; j <= 6; j++)
      dp[i] += dp[max(0, i-j)] * ps[j];
  }

  int T;
  cin >> T;

  for (int t = 0; t < T; t++) {
    int n;
    cin >> n;
    cout << fixed << setprecision(12) << dp[n] << endl;
  }
  
  return 0;
}
0