Created
April 28, 2012 04:56
-
-
Save SAPikachu/2516126 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
from pprint import pprint | |
def solve(): | |
line1 = [int(x) for x in sys.stdin.readline().strip().split(" ")] | |
typed = line1[0] | |
total = line1[1] | |
probs = [float(x) for x in sys.stdin.readline().strip().split(" ")] | |
min_expected = total + 2 | |
correct_prob = 1.0 | |
for i in range(typed): | |
correct_prob = correct_prob * probs[i] | |
chars_keep = i + 1 | |
keystrokes_if_correct = (typed - chars_keep) + (total - chars_keep) + 1 | |
keystrokes_if_not_correct = keystrokes_if_correct + total + 1 | |
expected = keystrokes_if_correct * correct_prob + keystrokes_if_not_correct * (1.0 - correct_prob) | |
if expected < min_expected: | |
min_expected = expected | |
return min_expected | |
def run(): | |
cases = int(sys.stdin.readline().strip()) | |
for i in range(cases): | |
print("Case #{}: {}".format(i + 1, solve())) | |
if __name__ == "__main__": | |
run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment