[프로그래머스 PCCP 모의고사 4번] 보물 지도
from collections import deque def solution(n, m, hole): dx = [-1,1,0,0] dy = [0,0,-1,1] area = [[0]*n for _ in range(m)] visited = [[[-1]*n for _ in range(m)] for _ in range(2)] for hx, hy in hole: area[hy-1][hx-1] = -1 area[0][0],area[m-1][n-1] = 1, 2 def bfs(): visited[0][0][0] = 0 queue = deque([(0,0,0)]) while queue: w, x, y = queue.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] ..
2023. 11. 11.
[프로그래머스 PCCP 모의고사 1번] 실습용 로봇
def solution(command): answer = [] # 로봇은 입력된 명령에 따라 x, y좌표를 이동 # G : 바라보는 방향으로 한칸 전진 # B : 바라보는 방향으로 한칸 후진 # 위, 오른, 아래, 왼 dx = [0,1,0,-1] dy = [1,0,-1,0] direction = 0 x,y = 0, 0 command = list(command) for com in command: if com == "R": direction = (direction + 1)%4 elif com == "L": if direction > 0: direction -= 1 else: direction = 3 elif com == "G": x += dx[direction] y += dy[direction] elif ..
2023. 11. 11.