結果

問題 No.75 回数の期待値の問題
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-11-24 18:48:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,023 ms / 5,000 ms
コード長 764 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 56,452 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 22:49:09
合計ジャッジ時間 85,818 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4,018 ms
4,380 KB
testcase_01 AC 4,017 ms
4,376 KB
testcase_02 AC 4,018 ms
4,380 KB
testcase_03 AC 4,018 ms
4,380 KB
testcase_04 AC 4,016 ms
4,380 KB
testcase_05 AC 4,018 ms
4,376 KB
testcase_06 AC 4,023 ms
4,376 KB
testcase_07 AC 4,017 ms
4,376 KB
testcase_08 AC 4,018 ms
4,380 KB
testcase_09 AC 4,016 ms
4,380 KB
testcase_10 AC 4,017 ms
4,376 KB
testcase_11 AC 4,017 ms
4,380 KB
testcase_12 AC 4,016 ms
4,376 KB
testcase_13 AC 4,020 ms
4,376 KB
testcase_14 AC 4,018 ms
4,376 KB
testcase_15 AC 4,018 ms
4,376 KB
testcase_16 AC 4,017 ms
4,380 KB
testcase_17 AC 4,018 ms
4,376 KB
testcase_18 AC 4,018 ms
4,380 KB
testcase_19 AC 4,017 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<ctime>
#include<map>

unsigned int xor128()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t = x^(x<<11);
	x = y; y = z; z = w;
	return w=(w^w>>19)^(t^(t>>8));
}

std::map<int, int> m;

int main()
{
	int K;
	scanf( "%d", &K );

	clock_t t = clock();
	int total = 0;
	while( clock() <= t+4*CLOCKS_PER_SEC )
	{
		int sum = 0, cnt = 0;

		for(;;)
		{
			int n = xor128()%6+1;
			sum += n;

			++cnt;

			if( sum == K )
				break;
			if( sum > K )
				sum = 0;
		}

		++m[cnt];
		++total;
	}

	double ans = 0;
	for( auto it = m.begin(); it != m.end(); ++it )
		ans += (double)it->first*it->second/total;

	printf( "%.2f\n", ans );

	return 0;
}
0