結果

問題 No.65 回数の期待値の練習
ユーザー htensaihtensai
提出日時 2019-12-06 12:42:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 626 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 71,468 KB
実行使用メモリ 57,804 KB
最終ジャッジ日時 2023-08-24 19:50:39
合計ジャッジ時間 5,437 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,652 KB
testcase_01 AC 121 ms
55,696 KB
testcase_02 AC 121 ms
55,824 KB
testcase_03 AC 122 ms
55,616 KB
testcase_04 AC 122 ms
55,648 KB
testcase_05 AC 121 ms
55,728 KB
testcase_06 AC 122 ms
55,708 KB
testcase_07 AC 121 ms
56,124 KB
testcase_08 AC 122 ms
55,628 KB
testcase_09 AC 121 ms
55,568 KB
testcase_10 AC 122 ms
55,776 KB
testcase_11 AC 123 ms
57,804 KB
testcase_12 AC 121 ms
55,812 KB
testcase_13 AC 120 ms
55,820 KB
testcase_14 AC 121 ms
55,944 KB
testcase_15 AC 120 ms
55,832 KB
testcase_16 AC 122 ms
55,972 KB
testcase_17 AC 121 ms
55,932 KB
testcase_18 AC 121 ms
55,968 KB
testcase_19 AC 121 ms
55,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double[] arr = new double[n + 1];
		arr[0] = 1;
		double ans = 0;
		for (int i = 1; i <= n; i++) {
		    double[] next = new double[n + 1];
		    for (int j = 0; j < n; j++) {
		        for (int k = 1; k <= 6; k++) {
		            if (j + k >= n) {
		                next[n] += arr[j] / 6;
		            } else {
		                next[j + k] += arr[j] / 6;
		            }
		        }
		    }
		    ans += next[n] * i;
		    arr = next;
		}
		System.out.println(ans);
   }
}

0