結果

問題 No.75 回数の期待値の問題
ユーザー Grenache
提出日時 2015-08-13 19:21:26
言語 Java
(openjdk 23)
結果
AC  
実行時間 119 ms / 5,000 ms
コード長 640 bytes
コンパイル時間 3,479 ms
コンパイル使用メモリ 74,740 KB
実行使用メモリ 54,088 KB
最終ジャッジ日時 2024-07-18 09:15:43
合計ジャッジ時間 5,700 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder75_2 {

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

        int k = sc.nextInt();

        double[] a = new double[k + 1];
        double[] b = new double[k + 1];
        for (int i = k - 1; i >= 0; i--) {
        	b[i] = 1;
        	for (int j = 1; j <= 6; j++) {
        		if (i + j > k) {
        			a[i] += (double)1 / 6;
        		} else {
        			a[i] += a[i + j] / 6;
        			b[i] += b[i + j] / 6;
        		}
        	}
        }
        
        System.out.printf("%.3f\n", b[0] / (1 - a[0]));

        sc.close();
    }
}
0