너비우선탐색

https://www.acmicpc.net/problem/11322코드from collections import dequen= int(input())def bfs(division): q = deque(["1"]) while q: num = q.popleft() if int(num) % division == 0: return num q.append(num+"0") q.append(num+"1")for i in range(n): print(bfs(int(input())))
https://www.acmicpc.net/problem/1261코드 (BFS)from collections import dequem, n = map(int, input().split())maze = [input() for _ in range(n)]dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]break_num = [[n*m]*m for _ in range(n)]break_num[0][0] = 0q = deque([(0, 0)])while q: x, y = q.popleft() for i in range(4): nx = x+dx[i] ny = y+dy[i] if 0 cnt: break_num[nx][ny] = ..
https://www.acmicpc.net/problem/1260 코드const dfs = (visit_num, visited, now, graph) => { if (visit_num == graph.length) { return; } dfs_path.push(now); // 현재 방문 노드 visited[now] = true; for (const nx of graph[now]) { if (!visited[nx]) { dfs(visit_num + 1, visited, nx, graph); } }};const bfs = (n, graph, start) => { let q = [start]; let visited = new Array(n + 1).fill(false);..
https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=4&contestProbId=AV14geLqABQCFAYD&categoryId=AV14geLqABQCFAYD&categoryType=CODE&problemTitle=&orderBy=PASS_RATE&selectCodeLang=PYTHON&select-1=4&pageSize=10&pageIndex=1 코드from collections import dequefor _ in range(10): tc, n = map(int, input().split()) arr = list(map(int, input().split())) graph = [[] for _ in r..
https://www.acmicpc.net/problem/6593 코드from collections import dequedx = [1, -1, 0, 0, 0, 0]dy = [0, 0, 1, -1, 0, 0]dz = [0, 0, 0, 0, 1, -1]while True: l, r, c = map(int, input().split()) if l == 0 and r == 0 and c == 0: break q = deque() visited = [[[False]*c for _ in range(r)] for _ in range(l)] dest = [] cube = [[] for _ in range(l)] for i in range(l): for j..
딜레이레이
'너비우선탐색' 태그의 글 목록