Advertisement
nq1s788

19 20 21 две кучи странные

Apr 12th, 2025
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #19 20 21 https://inf-ege.sdamgia.ru/test?id=17982110
  2. from functools import lru_cache
  3.  
  4.  
  5. def moves(h):
  6.     ret = []
  7.     x, y = h
  8.     if y < x:
  9.         x, y = y, x
  10.     for add in range(1, x + 1):
  11.         ret.append((x + add, y))
  12.     return ret
  13.  
  14.  
  15. @lru_cache(None)
  16. def game(h):
  17.     if sum(h) > 39:
  18.         return 'WIN'
  19.     elif any(game(m) == 'WIN' for m in moves(h)):
  20.         return 'P1'
  21.     elif all(game(m) in ['P1'] for m in moves(h)):
  22.         return 'V1'
  23.     elif any(game(m) == 'V1' for m in moves(h)):
  24.         return 'P2'
  25.     elif all(game(m) in ['P1', 'P2'] for m in moves(h)):
  26.         return 'V2'
  27.  
  28.  
  29. def p19(h):
  30.     return any(game(m) == 'P1' for m in moves(h))
  31.  
  32.  
  33. a19 = 100000000
  34. for fi in range(1, 39):
  35.     for se in range(fi, 39):
  36.         if fi + se > 39:
  37.             continue
  38.         if game((fi, se)) == 'P1':
  39.             a19 = min(a19, fi+se)
  40. print(a19)
  41.  
  42. #print([s for s in range(1, 72) if p19((14, s))]) #ваня выиграл первым ходом
  43. print([s for s in range(1, 36) if game((4, s)) == 'P2']) #петя вторым ходом
  44. print([s for s in range(1, 36) if game((4, s)) == 'V2'])
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement