結果

問題 No.75 回数の期待値の問題
ユーザー kou6839kou6839
提出日時 2015-03-13 00:55:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,306 ms / 5,000 ms
コード長 461 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 75,360 KB
実行使用メモリ 54,380 KB
最終ジャッジ日時 2024-06-28 22:46:25
合計ジャッジ時間 9,582 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.beans.IntrospectionException;
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans=0;
		Random random = new Random();
		for(int i=0;i<500000;i++){
			int count=0;
			int now=0;
			while(true){
				now+=(int)(random.nextInt(6))+1;
				count++;
				if(now==n) break;
				if(now>n) now=0;
			}
			ans+=count;
		}
		System.out.println(ans*1.0/500000);
	}
}
0