Advertisement
Guest User

855

a guest
Apr 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. def push(stack, way1):
  2.     '''
  3.    Переместить 1 вагон с 1-го пути в
  4.    '''
  5.     stack.append(way1.pop())
  6.  
  7.  
  8. def pull(way2, stack):
  9.     '''
  10.    Переместить 1 вагон из тупика на 2-й путь
  11.    '''
  12.     way2.append(stack.pop())
  13.    
  14.    
  15. def push_train(stack, way1, cnt=0):
  16.     '''
  17.    Переместить вагоны в тупик пока следующий вагон по номеру меньше предыдущего
  18.    или если тупик пуст
  19.    '''
  20.     if not way1:
  21.         return 0
  22.     elif not stack or stack[-1] >= way1[-1]:
  23.         push(stack, way1)
  24.         cnt += push_train(stack, way1, cnt)
  25.         return cnt + 1
  26.     elif stack[-1] < way1[-1]:
  27.         return 0
  28.        
  29.            
  30.            
  31.        
  32.        
  33.    
  34.  
  35.  
  36. n = int(input())
  37. way1 = [int(x) for x in input().split()]
  38. way1.reverse()
  39. stack = []
  40. print(push_train(stack, way1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement