結果

問題 No.76 回数の期待値で練習
ユーザー salicinasalicina
提出日時 2021-03-08 00:23:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 505 ms / 5,000 ms
コード長 1,443 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 96,960 KB
実行使用メモリ 18,400 KB
最終ジャッジ日時 2024-04-17 16:34:20
合計ジャッジ時間 1,789 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip> //<<setprecision(12), or <<fixed
#include <algorithm>
#include <functional>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
 
using namespace std;

using ll=long long;
using ull=unsigned long long;
using pll=pair<ll,ll>;

int main()
{
    vector<double> X(6,0);
    vector<double> r={  1.0833333333333333,
                        1.2569444444444444,
                        1.5353009259259260,
                        1.6915991512345676,
                        2.0513639724794235  };
                        
    auto search=[&](ll K)
    {
        K+=2; //E_K+2=0, solve E_0
        vector<double> dp(K+6+1,0);
        
        for(ll i=K-1; i>=0; i--)
        {
            dp[i]+=1;
            for(ll k=0; k<6; k++)
            {
                dp[i]+=dp[i+k+1]*X[k];
            }
        }
        K-=2;
        
        X[K]=r[K]-dp[0];
    };
    
    double sum=0;
    for(ll i=0; i<5; i++){ search(i); sum+=X[i]; }
    X[5]=1-sum;
    
    //query
    ll N;
    cin>>N;
    
    while(--N>=0)
    {
        ll T;
        cin>>T;
        
        vector<double> dp(T+6+1,0);
        for(ll i=T-1; i>=0; i--)
        {
            dp[i]+=1;
            for(ll k=0; k<6; k++)
            {
                dp[i]+=dp[i+k+1]*X[k];
            }
        }
        
        cout<<fixed<<setprecision(15)<<dp[0]<<endl;
    }

    // Fear misreading.
    return 0;
}
0