結果

問題 No.76 回数の期待値で練習
ユーザー tsutajtsutaj
提出日時 2018-01-25 10:37:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 1,686 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 97,796 KB
実行使用メモリ 11,420 KB
最終ジャッジ日時 2023-08-27 05:46:53
合計ジャッジ時間 1,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
11,420 KB
testcase_01 AC 25 ms
11,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

double info[7] = {0, 1.0000000000000000, 1.0833333333333333, 1.2569444444444444, 1.5353009259259260, 1.6915991512345676, 2.0513639724794235};
double p[7], dp[1000010];

signed main() {
    p[6] = 1.0;
    for(int k=2; k<=6; k++) {
        double val = info[k] - 1;
        for(int x=1; x<k-1; x++) val -= info[k-x] * p[x];
        p[k-1] = val;
        p[6] -= val;
    }

    for(int k=1; k<1000010; k++) {
        for(int x=1; x<=min(6LL, k); x++) {
            dp[k] += p[x] * dp[k-x];
        }
        dp[k] += 1;
    }

    int T; scanf("%lld", &T);
    while(T--) {
        int V; scanf("%lld", &V);
        printf("%.12f\n", dp[V]);
    }
    return 0;
}
0