結果
問題 | No.301 サイコロで確率問題 (1) |
ユーザー | siman |
提出日時 | 2023-04-03 18:12:41 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 64 ms / 1,000 ms |
コード長 | 1,027 bytes |
コンパイル時間 | 1,149 ms |
コンパイル使用メモリ | 131,640 KB |
実行使用メモリ | 4,348 KB |
最終ジャッジ日時 | 2023-10-25 05:24:31 |
合計ジャッジ時間 | 1,738 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 64 ms
4,348 KB |
testcase_01 | AC | 37 ms
4,348 KB |
コンパイルメッセージ
main.cpp:35:15: warning: implicit conversion from 'long long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-const-int-float-conversion] double ok = LLONG_MAX; ~~ ^~~~~~~~~ /usr/lib/llvm-14/lib/clang/14.0.0/include/limits.h:102:20: note: expanded from macro 'LLONG_MAX' #define LLONG_MAX __LONG_LONG_MAX__ ^~~~~~~~~~~~~~~~~ <built-in>:104:27: note: expanded from here #define __LONG_LONG_MAX__ 9223372036854775807LL ^~~~~~~~~~~~~~~~~~~~~ 1 warning generated.
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <limits.h> #include <map> #include <queue> #include <set> #include <string.h> #include <vector> using namespace std; typedef long long ll; double f(int K, double x) { vector<double> dp(K + 1, 0.0); for (int i = 1; i <= K; ++i) { for (int j = 1; j <= 6; ++j) { if (j > i) { dp[i] += x; } else { dp[i] += dp[i - j]; } } dp[i] = dp[i] / 6.0 + 1; } return dp[K]; } double solver(int K) { double ok = LLONG_MAX; double ng = 0; for (int i = 0; i < 100; ++i) { double x = (ok + ng) / 2.0; if (f(K, x) <= x) { ok = x; } else { ng = x; } } return ok; } int main() { int T; cin >> T; for (int i = 0; i < T; ++i) { ll N; cin >> N; if (N <= 200) { cout << fixed << setprecision(15) << solver(N) << endl; } else { cout << fixed << setprecision(15) << 5.0 / 3 + N << endl; } } return 0; }