結果
問題 |
No.425 ジャンケンの必勝法
|
ユーザー |
![]() |
提出日時 | 2025-06-12 15:07:07 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,539 bytes |
コンパイル時間 | 237 ms |
コンパイル使用メモリ | 82,476 KB |
実行使用メモリ | 63,156 KB |
最終ジャッジ日時 | 2025-06-12 15:08:18 |
合計ジャッジ時間 | 2,243 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 2 |
other | AC * 5 WA * 13 |
ソースコード
def main(): import sys p0, q = map(int, sys.stdin.readline().split()) p0_percent = p0 / 100.0 q_percent = q / 100.0 # Convert q to percentage change q_change = q # since p is in [0, 100], q is in [0, 100] # Initialize F[p] for all p in 0-100 F = [0.5] * 101 max_iterations = 100000 threshold = 1e-9 for _ in range(max_iterations): new_F = F.copy() max_diff = 0.0 for p in range(101): current_p = p / 100.0 # Compute probabilities P_N = current_p * 0.5 + (1 - current_p) * (1/3) P_C = (1 - current_p) * (1/3) P_Tie = current_p * 0.5 + (1 - current_p) * (1/3) # Compute next p values next_p_minus = max(p - q_change, 0) next_p_plus = min(p + q_change, 100) # Calculate E prob_strategy = current_p prob_no_strategy = 1 - current_p E = prob_strategy * F[next_p_minus] + prob_no_strategy * F[next_p_plus] # Update new_F[p] new_F_val = P_N * 1 + P_Tie * E new_F[p] = new_F_val # Update max_diff diff = abs(new_F[p] - F[p]) if diff > max_diff: max_diff = diff # Check for convergence if max_diff < threshold: break F = new_F # After convergence, compute the initial probability P initial_P = (1/3) + (1/3) * F[p0] print("{0:.10f}".format(initial_P)) if __name__ == '__main__': main()