結果
問題 | No.75 回数の期待値の問題 |
ユーザー |
![]() |
提出日時 | 2015-11-17 16:16:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 618 ms / 5,000 ms |
コード長 | 526 bytes |
コンパイル時間 | 175 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 77,312 KB |
最終ジャッジ日時 | 2024-09-13 16:50:36 |
合計ジャッジ時間 | 5,239 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
#!/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()