結果

問題 No.75 回数の期待値の問題
ユーザー kou6839kou6839
提出日時 2015-03-13 00:55:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,483 ms / 5,000 ms
コード長 461 bytes
コンパイル時間 2,337 ms
コンパイル使用メモリ 73,268 KB
実行使用メモリ 57,996 KB
最終ジャッジ日時 2023-09-11 08:13:36
合計ジャッジ時間 11,717 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 186 ms
55,936 KB
testcase_01 AC 189 ms
56,080 KB
testcase_02 AC 188 ms
55,612 KB
testcase_03 AC 215 ms
55,756 KB
testcase_04 AC 189 ms
55,500 KB
testcase_05 AC 187 ms
55,752 KB
testcase_06 AC 185 ms
56,060 KB
testcase_07 AC 214 ms
55,820 KB
testcase_08 AC 217 ms
55,844 KB
testcase_09 AC 220 ms
55,932 KB
testcase_10 AC 227 ms
55,712 KB
testcase_11 AC 234 ms
57,996 KB
testcase_12 AC 245 ms
56,000 KB
testcase_13 AC 257 ms
55,756 KB
testcase_14 AC 255 ms
55,452 KB
testcase_15 AC 287 ms
55,752 KB
testcase_16 AC 708 ms
56,028 KB
testcase_17 AC 1,154 ms
55,440 KB
testcase_18 AC 1,353 ms
55,568 KB
testcase_19 AC 1,483 ms
55,756 KB
権限があれば一括ダウンロードができます

ソースコード

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