結果

問題 No.75 回数の期待値の問題
コンテスト
ユーザー myanta
提出日時 2017-05-29 23:48:20
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 723 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 469 ms
コンパイル使用メモリ 61,440 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2026-04-09 23:46:22
合計ジャッジ時間 1,653 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<cstdio>
#include<vector>


using namespace std;

using pid=pair<int,double>;
using vd=vector<long double>;
using vvd=vector<vd>;


int main(void)
{
	int k, i, j, l, n;
	vvd c;
	long double r=1.0/6, ans;

	while(scanf("%d", &k)==1)
	{
		c.resize(1000);
		for(auto&ce:c) ce.assign(k+1, 0.0);
		c[0][0]=1.0;
		for(i=1;i<c.size();i++)
		{
			for(j=0;j<k;j++)
			{
				for(l=1;l<=6;l++)
				{
					n=j+l;
					if(n>k) n=0;
					c[i][n]+=c[i-1][j]*r;
				}
			}
		}
/*
printf("--- dump start ---\n");
for(auto&ce:c)
{
	for(auto cee:ce) printf("%.3f ", cee);
	printf("\n");
}
printf("--- dump end ---\n");
*/
		ans=0.0;
		for(i=1;i<c.size();i++)
		{
			ans+=i*c[i][k];
		}
		printf("%f\n" ,(double)ans);
	}

	return 0;
}
0