반응형
from collections import deque
def DFS(idx,idy,sheep,wolf):
global sheeps; global wolfs
visited[idx][idy] = True
for x,y in zip(dx,dy):
if 0<= x+idx < R and 0<= y+idy < C and visited[x+idx][y+idy] == False and graph[idx+x][idy+y] != '#':
if graph[idx+x][idy+y] == 'v':
DFS(idx+x,idy+y,sheep,wolf+1)
elif graph[idx+x][idy+y] == 'k':
DFS(idx+x,idy+y,sheep+1,wolf)
elif graph[idx+x][idy+y] == '.':
DFS(idx+x,idy+y,sheep,wolf)
if __name__ == '__main__':
R, C = map(int,input().split())
#graph = [list(input().split()) for _ in range(C)]
graph =[['...#..'], ['.##v#.'], ['#v.#.#'], ['#.k#.#'], ['.###.#'], ['...###']]
queue = deque([[1,3],[2,1],[3,2]])
visited = [[False] * C for _ in range(R)]
dx = [1,0,0,-1]; dy = [0,1,-1,0]
answer_sheep=0; answer_wolf = 0
while queue:
sheeps = 0; wolfs = 0
nx,ny = queue.popleft()
DFS(nx,ny,0,0)
if sheeps > wolfs:
answer_sheep += sheeps
else:
answer_wolf += wolfs
반응형
'IT 인터넷 > 백준 문제 풀이 정리장' 카테고리의 다른 글
상근이의여행 (0) | 2023.01.23 |
---|---|
N_Queen (0) | 2023.01.23 |
백준 1110번 (더하기 사이클) - C/C++ (0) | 2022.03.19 |
백준 2798번 (블랙잭) - Python3 파이썬 (0) | 2022.03.18 |
백준 (10870번) 피보나치 수 5 - Python3 파이썬 (0) | 2022.03.15 |