結果

問題 No.75 回数の期待値の問題
ユーザー GrenacheGrenache
提出日時 2015-08-13 19:21:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 640 bytes
コンパイル時間 5,353 ms
コンパイル使用メモリ 71,964 KB
実行使用メモリ 55,956 KB
最終ジャッジ日時 2023-09-25 11:28:45
合計ジャッジ時間 6,960 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,740 KB
testcase_01 AC 129 ms
55,852 KB
testcase_02 AC 131 ms
55,904 KB
testcase_03 AC 134 ms
55,568 KB
testcase_04 AC 132 ms
55,820 KB
testcase_05 AC 131 ms
55,584 KB
testcase_06 AC 131 ms
55,860 KB
testcase_07 AC 130 ms
55,956 KB
testcase_08 AC 129 ms
55,624 KB
testcase_09 AC 132 ms
55,400 KB
testcase_10 AC 132 ms
55,940 KB
testcase_11 AC 132 ms
55,744 KB
testcase_12 AC 131 ms
55,828 KB
testcase_13 AC 135 ms
55,736 KB
testcase_14 AC 131 ms
55,580 KB
testcase_15 AC 131 ms
55,924 KB
testcase_16 AC 131 ms
55,936 KB
testcase_17 AC 134 ms
55,568 KB
testcase_18 AC 131 ms
55,568 KB
testcase_19 AC 131 ms
55,856 KB
権限があれば一括ダウンロードができます

ソースコード

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