結果

問題 No.75 回数の期待値の問題
ユーザー pessimist
提出日時 2025-06-18 02:02:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 624 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 191,840 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-06-18 02:02:48
合計ジャッジ時間 3,184 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N;
double dp[201];
double test(double d){
    int i,j;
    for(i=1;i<=N;++i){
        dp[i]=0;
        for(j=1;j<=6;++j){
            if(j==i) dp[i]+=0;
            else if(j>i) dp[i]+=d;
            else dp[i]+=dp[i-j];
        }
        dp[i]=dp[i]/6.0+1;
    }
    return dp[N];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); 
    cin>>N;
    double l=0,r=1e10;
    for(int i_=0;i_<100;++i_){
        auto m=(l+r)/2.;
        if(test(m)>=m) l=m;
        else r=m;
    }
    cout<<fixed<<setprecision(15)<<(l+r)/2.<<endl;
    return 0;
}
0