結果

問題 No.75 回数の期待値の問題
ユーザー はむ吉🐹はむ吉🐹
提出日時 2015-11-17 16:16:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 648 ms / 5,000 ms
コード長 526 bytes
コンパイル時間 885 ms
コンパイル使用メモリ 86,524 KB
実行使用メモリ 78,856 KB
最終ジャッジ日時 2023-10-11 17:51:05
合計ジャッジ時間 6,844 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
78,312 KB
testcase_01 AC 183 ms
78,604 KB
testcase_02 AC 187 ms
78,856 KB
testcase_03 AC 169 ms
78,108 KB
testcase_04 AC 176 ms
78,800 KB
testcase_05 AC 182 ms
78,472 KB
testcase_06 AC 171 ms
78,552 KB
testcase_07 AC 168 ms
78,140 KB
testcase_08 AC 170 ms
78,024 KB
testcase_09 AC 166 ms
78,148 KB
testcase_10 AC 185 ms
78,160 KB
testcase_11 AC 178 ms
78,104 KB
testcase_12 AC 179 ms
78,192 KB
testcase_13 AC 186 ms
78,052 KB
testcase_14 AC 185 ms
78,188 KB
testcase_15 AC 195 ms
78,816 KB
testcase_16 AC 363 ms
78,144 KB
testcase_17 AC 527 ms
78,284 KB
testcase_18 AC 607 ms
78,068 KB
testcase_19 AC 648 ms
78,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import random

EXP_TIMES = 50000


def roll_dice(k):
    n = 0
    s = 0
    while True:
        s += random.randint(1, 6)
        n += 1
        if s == k:
            return n
        elif s < k:
            continue
        else:
            s = 0
            continue


def get_expectation(k, e=EXP_TIMES):
    return sum(float(roll_dice(k)) for i in range(EXP_TIMES)) / float(e)


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

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