SWEA-연산


SWEA-연산

# 자연수 N에 몇 번의 연산을 통해 M을 만들 수 있는가 # 사용할 수 있는 연산 +1, -1, *2, -10 def bfs(N, M): while queue: # 큐에서 하나씩 꺼내 목표 값이랑 같은지 비교 queue.pop(0) if queue[0][0] == M: result = queue[0][1] break # 다르면 다시 큐의 값을 계산하여 큐의 뒤에 삽입 # 이것을 반복하면서 계속 값을 비교 for i in queue: for j in numbers: if j == 2 and i[0] * j > 0 and i[0] * j <= M + 1 and not visited[i[0] * j]: visited[i[0] * j] = 1 queue.append([i[0] * j, i[1] + 1]) else: if i[0] + j > 0 and i[0] + j <= M + 1 and not visited[i[0] + j]: visited[i[0] + j] = 1 queue.appen...


#python #SWEA #문제풀이 #알고리즘 #연산

원문링크 : SWEA-연산