結果

問題 No.65 回数の期待値の練習
ユーザー YamaKasa
提出日時 2018-09-28 22:25:19
言語 Java
(openjdk 23)
結果
AC  
実行時間 306 ms / 5,000 ms
コード長 533 bytes
コンパイル時間 2,271 ms
コンパイル使用メモリ 74,024 KB
実行使用メモリ 41,660 KB
最終ジャッジ日時 2024-10-12 06:49:30
合計ジャッジ時間 8,083 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int K = scan.nextInt();
		scan.close();
		int n = 1000000;
		int a;
		if(K % 6 != 0) {
			a = K / 6 + 1;
		}else {
			a = K / 6;
		}
		int cnt = 0;
		double ans = 0;
		for(int i = 0; i < n; i++) {
			int p = 0;
			for(int j = 1; j <= K; j++) {
				p += (int)(Math.random() * 6) + 1;
				if(p >= K) {
					cnt += j;
					break;
				}
			}
		}
		ans += (double) cnt / n;
		System.out.println(ans);

	}
}
0