結果

問題 No.75 回数の期待値の問題
ユーザー myantamyanta
提出日時 2017-05-29 23:48:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 723 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 42,084 KB
実行使用メモリ 9,700 KB
最終ジャッジ日時 2023-10-21 17:00:54
合計ジャッジ時間 1,221 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 7 ms
6,108 KB
testcase_17 AC 12 ms
8,264 KB
testcase_18 AC 14 ms
9,264 KB
testcase_19 AC 15 ms
9,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(2000);
		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