結果

問題 No.75 回数の期待値の問題
ユーザー cielciel
提出日時 2014-11-24 23:21:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,882 ms / 5,000 ms
コード長 589 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 62,720 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 22:44:49
合計ジャッジ時間 13,699 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
4,380 KB
testcase_01 AC 106 ms
4,376 KB
testcase_02 AC 116 ms
4,380 KB
testcase_03 AC 175 ms
4,376 KB
testcase_04 AC 115 ms
4,376 KB
testcase_05 AC 109 ms
4,380 KB
testcase_06 AC 107 ms
4,380 KB
testcase_07 AC 176 ms
4,376 KB
testcase_08 AC 188 ms
4,376 KB
testcase_09 AC 194 ms
4,376 KB
testcase_10 AC 205 ms
4,376 KB
testcase_11 AC 222 ms
4,376 KB
testcase_12 AC 247 ms
4,376 KB
testcase_13 AC 259 ms
4,376 KB
testcase_14 AC 270 ms
4,376 KB
testcase_15 AC 347 ms
4,376 KB
testcase_16 AC 1,295 ms
4,376 KB
testcase_17 AC 2,270 ms
4,376 KB
testcase_18 AC 2,704 ms
4,380 KB
testcase_19 AC 2,882 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <random>
#include <cstdio>
#include <ctime>
#include <unistd.h>
using namespace std;

double expected(int n, int s, int t){//vector<int> b){
	int T=500000;
	int S=0;
	uniform_int_distribution<int> distribution(1,s);
	mt19937_64 engine((unsigned int)time(NULL)^(getpid()<<16));
	for(int I=0;I<T;I++){
		int turn=0;
		int cur=0;
		for(;cur!=t;){
			for(int i=0;i<n;i++)cur+=distribution(engine);
			if(cur>t)cur=0;
			turn++;
		}
		S+=turn;
	}
	return S*1.0/T;
}

int main(){
	int N;
	scanf("%d",&N);
	printf("%f\n",expected(1,6,N));
}
0