結果
| 問題 |
No.301 サイコロで確率問題 (1)
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2023-04-03 18:12:41 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 1,000 ms |
| コード長 | 1,027 bytes |
| コンパイル時間 | 1,222 ms |
| コンパイル使用メモリ | 141,604 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-25 00:49:32 |
| 合計ジャッジ時間 | 1,789 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 |
コンパイルメッセージ
main.cpp:35:15: warning: implicit conversion from 'long long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-const-int-float-conversion]
35 | double ok = LLONG_MAX;
| ~~ ^~~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/llvm/17.0.6_1/lib/clang/17/include/limits.h:107:20: note: expanded from macro 'LLONG_MAX'
107 | #define LLONG_MAX __LONG_LONG_MAX__
| ^~~~~~~~~~~~~~~~~
<built-in>:116:27: note: expanded from macro '__LONG_LONG_MAX__'
116 | #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;
}
siman