結果

問題 No.76 回数の期待値で練習
ユーザー otoshigootoshigo
提出日時 2023-02-21 16:51:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 1,039 bytes
コンパイル時間 771 ms
コンパイル使用メモリ 81,400 KB
実行使用メモリ 16,784 KB
最終ジャッジ日時 2023-09-29 08:50:58
合計ジャッジ時間 1,390 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(12);
    vector<double>p(6);
    rep(i,5){
        p[i]=e[i+1]-1;
        rep(j,i)p[i]-=p[j]*e[i-j];
    }
    p[5]=1;
    rep(i,5)p[5]-=p[i];
    for(int i=6;i<1e6;i++){
        double b=1;
        rep(j,6)b+=p[j]*e[i-1-j];
        e.push_back(b);
    }
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        n--;
        cout<<e[n]<<"\n";
    }
}
0