본문 바로가기

분류 전체보기443

[백준 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.
[백준 3190번] 뱀 from collections import deque n = int(input()) k = int(input()) area = [[0]*n for _ in range(n)] direction_list = [] time = 0 for _ in range(k): r,c = map(int,input().split()) area[r-1][c-1] = 1 l = int(input()) for _ in range(l): x, c = input().split() direction_list.append((int(x),c)) x, y = 0, 0 direction = "R" tail = deque([(0,0)]) index = 0 while 1: area[x][y] = -1 if time == direction_list.. 2023. 8. 6.
[백준 2206번] 벽 부수고 이동하기 from collections import deque n, m = map(int,input().split()) maze = [list(map(int,list(input()))) for _ in range(n)] visited = [[[0]*m for _ in range(n)] for _ in range(2)] dx = [-1,1,0,0] dy = [0,0,-1,1] def bfs(): visited[0][0][0] = 1 queue = deque([(0,0,0)]) while queue: w,x,y = queue.popleft() if x == n-1 and y == m-1: return visited[w][x][y] for i in range(4): nx = x + dx[i] ny = y + dy[i].. 2023. 8. 4.
[백준 14923번] 미로 탈출 from collections import deque dx = [-1,1,0,0] dy = [0,0,-1,1] n, m = map(int,input().split()) hx, hy = map(int,input().split()) ex, ey = map(int,input().split()) maze = [list(map(int,input().split())) for _ in range(n)] visited = [[[0]*m for _ in range(n)] for _ in range(2)] def bfs(): visited[0][hx-1][hy-1] = 0 queue = deque([(0,hx-1,hy-1)]) while queue: v = queue.popleft() w, x, y = v[0], v[1].. 2023. 8. 4.
[React] React 18 업데이트 내용 정리(Automatic Batching / Suspense / Transition) 1. Automatic Batching Batching 이란 ? 업데이트 대상이 되는 상태 값들을 하나로 묶어서 한번의 리렌더링으로 업데이트가 일괄적으로 진행될 수 있도록 하는 것 위처럼 하나의 함수 안에 있는 여러 setState는 비동기로 동작하며, 한번의 리렌더링으로 상태가 일괄적으로 업데이트됩니다. 함수의 끝에서 상태가 업데이트가 되며, 단 한번의 리렌더링이 이루어집니다. 👉🏻 불필요한 리렌더링을 방지함으로써 렌더링 성능을 개선시킬 수 있음 ! batch update를 통해 불필요한 리렌더링을 줄여줌으로써 성능적으로는 큰 이점을 얻을 수 있었고, 이전 버전에서도 이러한 batch update를 지원했지만 Click과 같은 React의 이벤트 핸들러 내부에서만 적용이 가능하고 Promise의 내부나.. 2023. 8. 2.
[프로그래머스 Lv.2] 게임 맵 최단거리 from collections import deque def solution(maps): n,m = len(maps), len(maps[0]) # 행 개수, 열 개수 dx = [-1,1,0,0] dy = [0,0,-1,1] visited = [[False]*m for _ in range(n)] queue = deque([(0,0)]) visited[0][0] = True while queue: x,y = queue.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if nx >= 0 and nx = 0 and ny < m and not visited[nx][ny] and maps[nx][ny] != 0: queue.append(.. 2023. 8. 2.