This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let p = probability that team A win | |
# M = amount of rupees bet on team A | |
# R = number of rupees = 10000 | |
# E = max expected rupees | |
# Hence, | |
# R-M = number of rupees bet on team B | |
# 1-p = probability that team B wins | |
# Expected rupees | |
# = p(M + M * (2-2p)) + (1-p)((R-M) + (R-M) * (2-2(1-p))) | |
# = pM + pM(2-2p) + (1-p)(R-M) + (1-p)(R-M)(2p) | |
# = pM + 2pM -2ppM + R-Rp -M +pM + (2p-2pp)(R-M) | |
# = 4pM - 2ppM +R-Rp-M + 2pR - 2ppR -2pM +2ppM | |
# = 2pM + R -Rp - M + 2pR - 2ppR | |
# = 2pM + R - M + pR - 2ppR | |
# = M(2p-1) + R - pR - 2ppR | |
# For each case, p and R are constant. | |
# Take the derivative of E against M | |
# to find value of M which E is greatest | |
# That value = 2p-1. | |
# If p > 0.5, increasing M will increase E | |
# If p < 0.5, increasing M will decrease E | |
# Hence if p > 0.5 bet everything on team A | |
# else if p < 0.5 bet everything on team B | |
# Verification: expected rupees | |
# = p[M( 1 + (2-2p))] + (1-p)[(R-M)(1+2p)] | |
# = pM(3 - 2p) + (R-M) (1+p-2pp) | |
# = 3pM - 2ppM + R + Rp - 2ppR - M - pM + 2ppM | |
# = 2pM + R + Rp - 2ppR - M | |
# = pM - M + pM + R + Rp - 2ppR | |
# = M(p-1) + pM + R(1+p-2pp) | |
import sys | |
T = int(sys.stdin.readline().strip()) | |
R = 10000 | |
for i in range(T): | |
p = float(sys.stdin.readline().strip()) | |
if p > 0.5: | |
print(p*(R+R*(2-2*p))) | |
else: | |
print((1-p)*(R+R*2*p)) |
No comments:
Post a Comment