結果

問題 No.75 回数の期待値の問題
ユーザー ciel
提出日時 2014-11-24 23:20:43
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 305 ms / 5,000 ms
コード長 589 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 70,476 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-02 21:14:54
合計ジャッジ時間 3,037 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |         scanf("%d",&N);
      |         ~~~~~^~~~~~~~~

ソースコード

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=200000;
	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