結果
問題 | No.301 サイコロで確率問題 (1) |
ユーザー |
|
提出日時 | 2019-09-10 20:36:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 434 ms / 1,000 ms |
コード長 | 986 bytes |
コンパイル時間 | 1,625 ms |
コンパイル使用メモリ | 168,312 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 16:19:49 |
合計ジャッジ時間 | 3,049 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 |
ソースコード
#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;}}}