Участник:Andriygav/Dice

Материал из DISCOPAL
Перейти к: навигация, поиск

https://www.spoj.com/problems/AE2A

import math
 
def solver(ns, ks):
    PROBA = 1/6
    answer = {1: PROBA, 
              2: PROBA, 
              3: PROBA, 
              4: PROBA, 
              5: PROBA, 
              6: PROBA}
 
    max_n = max(ns)
    answers = [0]*len(ns)
    for i in range(1, min(max_n+1, 546)):
        for j in range(len(ns)):
            n = ns[j]
            k = ks[j]
            if n == i:
                if k in answer:
                    answers[j] = math.floor(100*answer[k])
                else:
                    answers[j] = 0
 
 
        treshold = max(answer, key=lambda x:answer[x])
 
        new_answer = dict()
        for item in answer:
            if item < treshold - 90 or item > treshold + 90:
                continue
            for j in range(1, 7):
                new_answer[item+j] = new_answer.get(item+j, 0) + answer[item]
 
        answer = dict()
        for item in new_answer:
            answer[item] = new_answer[item]*PROBA
 
        if not len(answer):
            break
 
    return answers
 
t = int(input())
ns = []
ks = []
for i in range(t):
    n, k = list(map(int, input().split()))
    ns.append(n)
    ks.append(k)
 
answers = solver(ns, ks)
 
for ans in answers:
    print(ans)