結果

問題 No.76 回数の期待値で練習
ユーザー face4face4
提出日時 2019-09-27 14:58:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 5,000 ms
コード長 1,038 bytes
コンパイル時間 560 ms
コンパイル使用メモリ 69,860 KB
実行使用メモリ 70,200 KB
最終ジャッジ日時 2023-10-24 16:03:37
合計ジャッジ時間 1,220 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,808 KB
testcase_01 AC 77 ms
70,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
using namespace std;

const double d[6] = {0.083333333333, 0.166666666667, 0.250000000000, 0.083333333333, 0.250000000000, 0.166666666667};
bool memo[1000001] = {};
double b[1000001] = {};

double dfs(int x){
    if (x <= 0)     return 0;
    if (memo[x])    return b[x];
    memo[x] = true;
    b[x] = 1.0;
    for (int j = 1; j <= 6; j++)    b[x] += dfs(x-j)*d[j-1];
    return b[x];
}

int main(){
    /*  実験
    double d[6] = {}, a[7] = {};
    for(int i = 1; i <= 6; i++) cin >> a[i];
    for(int i = 2; i <= 6; i++){
        double tmp = a[i] - 1.0;
        for(int j = 1; j+1 < i; j++){
            tmp -= a[i-j]*d[j];
        }
        d[i-1] = tmp/a[1];
    }
    cout << fixed << setprecision(12);
    for(int i = 1; i <= 5; i++){
        cout << d[i] << endl;
    }
    cout << 1-d[1]-d[2]-d[3]-d[4]-d[5] << endl;
    */

    int q;
    cin >> q;
    while (q-- > 0){
        int n;
        cin >> n;
        cout << fixed << setprecision(15) << dfs(n) << endl;
    }

    return 0;
}
0