結果

問題 No.301 サイコロで確率問題 (1)
ユーザー simansiman
提出日時 2023-04-03 18:09:28
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,026 bytes
コンパイル時間 1,116 ms
コンパイル使用メモリ 131,460 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 05:24:26
合計ジャッジ時間 1,679 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 = INT_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) {
    int N;
    cin >> N;

    if (N <= 200) {
      cout << fixed << setprecision(10) << solver(N) << endl;
    } else {
      cout << fixed << setprecision(10) << 5.0 / 3 + N << endl;
    }
  }

  return 0;
}
0