結果

問題 No.75 回数の期待値の問題
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-21 10:40:04
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 870 bytes
コンパイル時間 1,222 ms
コンパイル使用メモリ 142,828 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 03:14:20
合計ジャッジ時間 2,248 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 13 ms
5,376 KB
testcase_17 AC 21 ms
5,376 KB
testcase_18 AC 26 ms
5,376 KB
testcase_19 AC 28 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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