結果

問題 No.76 回数の期待値で練習
ユーザー square1001square1001
提出日時 2016-11-05 14:29:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 5,000 ms
コード長 493 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 163,348 KB
実行使用メモリ 74,760 KB
最終ジャッジ日時 2023-08-16 13:53:07
合計ジャッジ時間 2,151 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int Q, N; bool vis[1000009]; double dp[1000009];
double r[] = { 1.0 / 12, 1.0 / 6, 1.0 / 4, 1.0 / 12, 1.0 / 4, 1.0 / 6 };
double rec(int x) {
	if(x <= 0) return 0.0;
	if(vis[x]) return dp[x];
	double ret = 0.0;
	for(int i = 1; i <= 6; i++) ret += rec(x - i) * r[i - 1];
	vis[x] = true;
	return dp[x] = ret + 1;
}
int main() {
	rec(1000000);
	cin >> Q;
	while(Q--) {
		cin >> N;
		cout << fixed << setprecision(15) << dp[N] << endl;
	}
	return 0;
}
0