結果

問題 No.301 サイコロで確率問題 (1)
ユーザー 👑 nu50218nu50218
提出日時 2019-09-10 20:36:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 410 ms / 1,000 ms
コード長 986 bytes
コンパイル時間 1,648 ms
コンパイル使用メモリ 165,776 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 13:08:19
合計ジャッジ時間 2,808 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 410 ms
4,380 KB
testcase_01 AC 22 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool check(long double imid, int N) {
    long double a[N + 1 + 6] = {};
    for (size_t i = 0; i < N + 1 + 6; i++) {
        if (i < 6) {
            a[i] = imid;
            continue;
        } else if (i == 6) {
            a[i] = 0;
        } else {
            a[i] = 1.0L;
            for (size_t j = 0; j < 6; j++) {
                a[i] += a[i - j - 1] / 6.0L;
            }
        }
    }
    return a[N + 6] < imid;
}

long double solve(int N) {
    long double imin = 0;
    long double imax = 1e20;
    for (size_t i = 0; i < 1000; i++) {
        long double imid = (imin + imax) / 2.0L;
        (check(imid, N) ? imax : imin) = imid;
    }
    return imax;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        long long N;
        cin >> N;
        if (N <= 200) {
            cout << setprecision(50) << solve(N) << endl;
        } else {
            cout << N + 1 << ".666666666666" << endl;
        }
    }
}
0