結果

問題 No.75 回数の期待値の問題
コンテスト
ユーザー ciel
提出日時 2014-11-24 23:21:30
言語 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
結果
AC  
実行時間 771 ms / 5,000 ms
コード長 589 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 440 ms
コンパイル使用メモリ 88,012 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-06 07:41:41
合計ジャッジ時間 4,886 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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