結果

問題 No.65 回数の期待値の練習
ユーザー はむ吉🐹はむ吉🐹
提出日時 2015-10-28 13:46:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 221 ms / 5,000 ms
コード長 426 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 10,696 KB
実行使用メモリ 10,416 KB
最終ジャッジ日時 2023-10-11 04:47:38
合計ジャッジ時間 4,918 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
10,208 KB
testcase_01 AC 87 ms
10,172 KB
testcase_02 AC 93 ms
10,344 KB
testcase_03 AC 123 ms
10,172 KB
testcase_04 AC 99 ms
10,236 KB
testcase_05 AC 107 ms
10,136 KB
testcase_06 AC 113 ms
10,364 KB
testcase_07 AC 128 ms
10,236 KB
testcase_08 AC 136 ms
10,352 KB
testcase_09 AC 144 ms
10,316 KB
testcase_10 AC 150 ms
10,360 KB
testcase_11 AC 159 ms
10,200 KB
testcase_12 AC 165 ms
10,416 KB
testcase_13 AC 172 ms
10,284 KB
testcase_14 AC 182 ms
10,364 KB
testcase_15 AC 189 ms
10,404 KB
testcase_16 AC 196 ms
10,348 KB
testcase_17 AC 203 ms
10,320 KB
testcase_18 AC 209 ms
10,176 KB
testcase_19 AC 221 ms
10,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import random
import statistics

EXP_TIMES = 50000


def roll_dice(k):
    n = 0
    s = 0
    while s < k:
        d = random.randint(1, 6)
        n += 1
        s += d
    return n


def get_expectation(k):
    return statistics.mean(float(roll_dice(k)) for i in range(EXP_TIMES))


def main():
    print(get_expectation(int(input())))

if __name__ == "__main__":
    main()
0