結果

問題 No.76 回数の期待値で練習
ユーザー otsnskotsnsk
提出日時 2014-12-25 20:59:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 1,401 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 61,944 KB
実行使用メモリ 11,484 KB
最終ジャッジ日時 2023-09-03 17:28:03
合計ジャッジ時間 1,233 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>

#define FORR(i,b,e) for(int i=(b);i<(int)(e);++i)
#define FOR(i,e) FORR(i,0,e)
#define dump(var) cerr << #var ": " << var << "\n"
#define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n"

typedef long long ll;
typedef unsigned long long ull;

using namespace std;


double p[6];  // = {1/12, 2/12, 3/12, 1/12, 3/12, 2/12};
double exref[] = {
    0,
    1.0000000000000000,
    1.0833333333333333,
    1.2569444444444444,
    1.5353009259259260,
    1.6915991512345676,
    2.0513639724794235,
};
double dp[1000100];

void bottomup(int e) {
    dp[0] = 0;
    FORR(i, 1, e+1) {
        dp[i] = 1;
        FOR(j, 6)
            if (i-j-1 >= 0) dp[i] += dp[i-j-1] * p[j];
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    fill(p, p+6, 0);
    FOR(k, 5) {
        double a = 0, b = 1, c;
        FOR(i, k) b -= p[i];
        
        FOR(m, 40) {  // bisection method 
            c = (a+b) / 2;
            p[k] = c;
            p[5] = 1;
            FOR(i, 5) p[5] -= p[i];
            bottomup(k+2);
            if (dp[k+2] > exref[k+2]) b = c;
            else a = c;
        }
        p[k] = c;
        p[5] = 1;
        FOR(i, 5) p[5] -= p[i];
    }

    bottomup(1000000);

    int T, N;
    cin >> T;
    while (T--) {
        cin >> N;
        cout << fixed << setprecision(6) << dp[N] << "\n";
    }
    
    return 0;
}
0