[프로그래머스] Lv2 - 게임 맵 최단거리 (파이썬)
https://programmers.co.kr/learn/courses/30/lessons/1844 코딩테스트 연습 - 게임 맵 최단거리 [[1,0,1,1,1],[1,0,1,0,1],[1,0,1,1,1],[1,1,1,0,1],[0,0,0,0,1]] 11 [[1,0,1,1,1],[1,0,1,0,1],[1,0,1,1,1],[1,1,1,0,0],[0,0,0,0,1]] -1 programmers.co.kr from collections import deque dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def solution(maps): global N, M N = len(maps)+1 M = len(maps[0])+1 maps = [[0]*(len(maps[0]))]+[[0]+map f..
2022. 4. 3.
[프로그래머스] Lv2 - 거리두기 확인하기 (파이썬)
https://programmers.co.kr/learn/courses/30/lessons/81302 코딩테스트 연습 - 거리두기 확인하기 [["POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"], ["POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"], ["PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"], ["OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"], ["PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"]] [1, 0, 1, 1, 1] programmers.co.kr from collections import deque dx = [0, 1, 0, -1] d..
2022. 4. 1.
[백준] 6087번 - 레이저 통신 (파이썬)
# 레이저 통신 from collections import deque import sys input = sys.stdin.readline MAX = sys.maxsize M, N = map(int, input().split()) arr = [] C = [] for i in range(N): arr.append(list(input().strip())) for j in range(M): if arr[i][j] == 'C': C.append((i, j)) start, end = C[0], C[1] dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def bfs(a, b): global answer q = deque() q.append((a, b, -1, 0)) visited = [[0] * ..
2022. 3. 21.
[프로그래머스] 고득점Kit (8) - DFS/BFS (파이썬)
1. 타겟 넘버 (Lv. 2) # 타겟 넘버 def solution(numbers, target): answer = 0 def dfs(target, k, result): nonlocal answer if k == len(numbers): if target == result: answer += 1 return else: dfs(target, k+1, result+numbers[k]) dfs(target, k+1, result-numbers[k]) dfs(target, 0, 0) return answer 재귀 함수를 이용한 dfs로 풀었다. k == len(numbers) 일 경우, target과 같은지 확인 return answer 2. 네트워크 (Lv. 3) # 네트워크 from collections i..
2022. 3. 11.
[백준] 4179번 - 불! (파이썬)
# 불! from collections import deque import sys input = sys.stdin.readline dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] N, M = map(int, input().split()) arr = [] now = deque() fire = deque() for i in range(N): arr.append(list(input().strip())) for j in range(M): if arr[i][j] == 'J': now.append((i, j)) arr[i][j] = 1 if arr[i][j] == 'F': fire.append((i, j)) def move(): leng = len(now) for _ in range(leng):..
2022. 3. 3.
[백준] 17472번 - 다리 만들기 2 (파이썬)
# 다리 만들기 2 from collections import deque import sys input = sys.stdin.readline MAX = sys.maxsize dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] N, M = map(int, input().split()) land = [] arr = [] for i in range(N): arr.append(list(map(int, input().split()))) for j in range(M): if arr[i][j] == 1: land.append((i, j)) def find_land(visited, a, b, num): q = deque() q.append((a, b)) while q: x, y = q.popleft(..
2022. 2. 19.