Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #19 20 21 https://inf-ege.sdamgia.ru/test?id=17982110
- from functools import lru_cache
- def moves(h):
- ret = []
- x, y = h
- if y < x:
- x, y = y, x
- for add in range(1, x + 1):
- ret.append((x + add, y))
- return ret
- @lru_cache(None)
- def game(h):
- if sum(h) > 39:
- return 'WIN'
- elif any(game(m) == 'WIN' for m in moves(h)):
- return 'P1'
- elif all(game(m) in ['P1'] for m in moves(h)):
- return 'V1'
- elif any(game(m) == 'V1' for m in moves(h)):
- return 'P2'
- elif all(game(m) in ['P1', 'P2'] for m in moves(h)):
- return 'V2'
- def p19(h):
- return any(game(m) == 'P1' for m in moves(h))
- a19 = 100000000
- for fi in range(1, 39):
- for se in range(fi, 39):
- if fi + se > 39:
- continue
- if game((fi, se)) == 'P1':
- a19 = min(a19, fi+se)
- print(a19)
- #print([s for s in range(1, 72) if p19((14, s))]) #ваня выиграл первым ходом
- print([s for s in range(1, 36) if game((4, s)) == 'P2']) #петя вторым ходом
- print([s for s in range(1, 36) if game((4, s)) == 'V2'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement