結果

問題 No.75 回数の期待値の問題
ユーザー srjywrdnprkt
提出日時 2022-12-21 10:40:04
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 870 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 144,748 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-18 02:39:32
合計ジャッジ時間 2,849 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <cassert>
 
using namespace std;

long long K;
vector<long double> ans;

long double f(long long n, long double x){
    if (n > K) return x;
    if (n == K) return 0.0;
    if (ans[n] != -1) return ans[n];
    long double res = 0.0;
    for (int i=1; i<=6; i++) res += f(n+i, x);
    return ans[n] = res / 6.0 + 1.0;
}

long double g(long double x){
    for (int i=0; i<=K; i++) ans[i] = -1;
    return f(0, x)-x;
}
 
int main(){
 
    cin >> K;
    ans.resize(K+1, -1);
    
    long double l=0, r=500, c;
    for (int i=0; i<1000; i++){
        c = (r+l)/2;
        if (g(c)*g(l) > 0) l = c;
        else r = c;
    }
 
    cout << setprecision(18) << c << endl;
 
    return 0;
}
0