結果

問題 No.76 回数の期待値で練習
ユーザー square1001square1001
提出日時 2016-11-05 14:28:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 490 bytes
コンパイル時間 1,970 ms
コンパイル使用メモリ 165,244 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-16 13:53:05
合計ジャッジ時間 2,033 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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(1000);
	cin >> Q;
	while(Q--) {
		cin >> N;
		cout << fixed << setprecision(15) << dp[N] << endl;
	}
	return 0;
}
0