[백준 14503번] 로봇 청소기
n,m = map(int,input().split()) r,c,d = map(int,input().split()) # 현재 방향을 기준으로 반시계방향으로 탐색 dx = [[0,1,0,-1],[-1,0,1,0],[0,-1,0,1],[1,0,-1,0]] dy = [[-1,0,1,0],[0,-1,0,1], [1,0,-1,0],[0,1,0,-1]] # 바라보는 방향이 북쪽인 경우 # dx_0 =[0,1,0,-1] # dy_0 =[-1,0,1,0] # 바라보는 방향이 동쪽인 경우 # dx_1 = [-1,0,1,0] # dy_1 = [0,-1,0,1] # 바라보는 방향이 남쪽인 경우 # dx_2 = [0,-1,0,1] # dy_2 = [1,0,-1,0] # 바라보는 방향이 서쪽인 경우 # dx_3 = [1,0,-1..
2023. 8. 9.
[백준 16234번] 인구 이동
from collections import deque import math N, L ,R = map(int,input().split()) data = [list(map(int,input().split())) for _ in range(N)] visited = [[False]*N for _ in range(N)] dx = [-1,1,0,0] dy = [0,0,-1,1] count = 0 def bfs(x,y): # 국경선을 열고 인구를 이동시키는 BFS 함수 if visited[x][y]: # 이미 방문한 곳이면 Pass return False visited[x][y] = True group = [(x,y)] # 연합을 이룬 좌표 목록 total = data[x][y] # 연합의 총합 queue = deq..
2023. 8. 7.