結果

問題 No.65 回数の期待値の練習
ユーザー Grenache
提出日時 2015-07-28 17:11:19
言語 Java
(openjdk 23)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 519 bytes
コンパイル時間 3,396 ms
コンパイル使用メモリ 74,404 KB
実行使用メモリ 54,372 KB
最終ジャッジ日時 2024-07-17 13:13:32
合計ジャッジ時間 6,971 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder65 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int k = sc.nextInt();

        double[] e = new double[k + 1];
        e[k] = 0.0;
        for (int i = k - 1; i >= 0; i--) {
        	e[i] = 1;
        	for (int j = 0; j < 6; j++) {
        		if (i + j + 1 <= k) {
        			e[i] += e[i + j + 1] / 6;
        		}
        	}
        }

        System.out.printf("%.3f\n", e[0]);

        sc.close();
    }
}
0