[백준 3184 파이썬 ] 양
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 # 3184 양 # BFS # PyPy3 180 ms # BFS 이동 dx = [0,1,0,-1] dy = [-1,0,1,0] def bfs(x,y): queue = [(x,y)] o, v = 0, 0 while queue: x, y = queue.pop() if board[x][y]=='v': v +=1 if board[x][y]=='o': o +=1 board[x][y]='#' for i in range(4): nx = x + dx[i] ny = y + dy..
더보기
[백준 7562 파이썬] 나이트 이동
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 # 7562 나이트 이동 # BFS # Pypy3 752ms dx = [-2, -1, 1, 2, -2, -1, 1 ,2] dy = [-1, -2, -2, -1,1, 2, 2, 1] def bfs(start, end): queue = [start] board[start[0]][start[1]]=1 while queue: pos = queue.pop(0) if end[0]==pos[0] and end[1]==pos[1]: return board[pos[0]][pos[1]]-1 for i in range(8): n..
더보기
[백준 2583 파이썬] 영역구하기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 # 2583 영역구하기 # BFS # Python 60ms M, N, K = map(int, input().split()) board = [[0 for _ in range(N)] for _ in range(M)] def color_board(Lx, Ly, Rx, Ry): for i in range(Lx, Rx): for j in range(Ly, Ry): board[j][i]= 1 for i in range(K): # Color the board Lx, Ly, ..
더보기