結果

問題 No.425 ジャンケンの必勝法
ユーザー maspymaspy
提出日時 2020-03-20 01:33:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,035 ms / 2,000 ms
コード長 617 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 29,680 KB
最終ジャッジ日時 2023-08-20 21:19:52
合計ジャッジ時間 15,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,030 ms
29,492 KB
testcase_01 AC 1,035 ms
29,552 KB
testcase_02 AC 148 ms
29,512 KB
testcase_03 AC 150 ms
29,456 KB
testcase_04 AC 472 ms
29,600 KB
testcase_05 AC 151 ms
29,508 KB
testcase_06 AC 341 ms
29,612 KB
testcase_07 AC 525 ms
29,568 KB
testcase_08 AC 207 ms
29,480 KB
testcase_09 AC 146 ms
29,608 KB
testcase_10 AC 150 ms
29,576 KB
testcase_11 AC 484 ms
29,644 KB
testcase_12 AC 521 ms
29,584 KB
testcase_13 AC 1,027 ms
29,628 KB
testcase_14 AC 641 ms
29,464 KB
testcase_15 AC 1,030 ms
29,460 KB
testcase_16 AC 1,022 ms
29,560 KB
testcase_17 AC 484 ms
29,624 KB
testcase_18 AC 152 ms
29,568 KB
testcase_19 AC 149 ms
29,488 KB
testcase_20 AC 587 ms
29,472 KB
testcase_21 AC 1,027 ms
29,660 KB
testcase_22 AC 1,025 ms
29,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

p0, q = map(int, read().split())
p0 /= 100
q /= 100


def solve(depth, p):
    if depth > 20:
        return 0.5
    if p < 0:
        p = 0
        return (1 / 3) + solve(depth + 1, p + q) / 3
    if p > 1:
        p = 1
        return (1 / 2) + solve(depth + 1, p - q) / 2
    x = (1 / 3) + solve(depth + 1, p + q) / 3
    y = (1 / 2) + solve(depth + 1, p - q) / 2
    return x * (1 - p) + y * p


x = solve(0, p0)
answer = 1 / 3 + x / 3
print(answer)
0