結果

問題 No.75 回数の期待値の問題
ユーザー nenuonnenuon
提出日時 2018-02-24 14:39:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 925 bytes
コンパイル時間 1,162 ms
コンパイル使用メモリ 97,268 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 13:11:28
合計ジャッジ時間 2,366 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <random>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
// 二分探索var
// dp[0] = x
int K;
double dp[222];
double calc(double x) {
  CLR(dp);
  for(int i = K - 1; i >= 0; i--) {
    FOR(j,1,7) {
      if(i + j > K) dp[i] += x;
      else dp[i] += dp[i+j];
    }
    dp[i] = dp[i] / 6.0 + 1;
  }
  return dp[0];
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> K;
  double l = 0, r = 1e9;
  FOR(i,0,100) {
    double c = (l + r) / 2;
    if(calc(c) >= c) l = c;
    else r = c;
  }
  cout << (l + r) / 2 << endl;
}
0