[Python] 카카오 2019 - 블록 게임
https://programmers.co.kr/learn/courses/30/lessons/42894 코딩테스트 연습 - 블록 게임 [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,4,0,0,0],[0,0,0,0,0,4,4,0,0,0],[0,0,0,0,3,0,4,0,0,0],[0,0,0,2,3,0,0,0,5,5],[1,2,2,2,3,3,0,0,0,5],[1,1,1,0,0,0,0,0,0,5]] 2 programmers.co.kr 풀이 유튜브 ezsw 에서 c++로 풀이 해주신 거(링크)를 python으로 짠 코드이다. 각 모양의 블럭을 어떻게 찾아야하나 DFS라도 해야하나 ..
2020. 8. 19.
[Python] 카카오 2020 인턴쉽 - 경주로 건설 (BFS)
from collections import deque def solution(board): ans = float('inf') n = len(board) dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] # (nx, ny, d) : cost visit = {(0,0,0):0, (0,0,1):0, (0,0,2) : 0, (0,0,3):0} que = deque() #초기값. x, y, dir = -1 , cost que.append((0,0,-1,0)) #BFS while que: x, y, dir, cost = que.popleft() for d in range(4): nx = x + dx[d] ny = y + dy[d] #이동 가능하면 (범위내이고 board[nx][ny]가 0이면) i..
2020. 8. 16.