結果

問題 No.76 回数の期待値で練習
ユーザー not_522not_522
提出日時 2015-08-20 02:34:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 1,378 ms
コンパイル使用メモリ 148,072 KB
実行使用メモリ 19,008 KB
最終ジャッジ日時 2023-09-25 13:43:08
合計ジャッジ時間 1,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  vector<double> p(7), v{0, 1.0000000000000000, 1.0833333333333333, 1.2569444444444444, 1.5353009259259260, 1.6915991512345676, 2.0513639724794235};
  for (int i = 1; i <= 5; ++i) {
    p[i] = v[i + 1] - 1;
    for (int j = 1; j < i; ++j) p[i] -= p[j] * v[i - j + 1];
  }
  p[6] = 1 - accumulate(p.begin(), p.end() - 1, 0.);
  for (int i = 7; i <= 1000000; ++i) {
    v.emplace_back(inner_product(p.begin() + 1, p.end(), v.rbegin(), 0.) + 1);
  }
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int n;
    cin >> n;
    cout << fixed << setprecision(15) << v[n] << endl;
  }
}
0