[python] 17472. 다리 만들기 2
문제 출처 17472. 다리 만들기 2 풀이 from collections import deque N, M = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(N)] visited = [[0]*M for _ in range(N)] dx, dy = (1, 0, -1, 0), (0, 1, 0, -1) def numbering_irlands(x, y): visited[y][x] = 1 arr[y][x] = irland q = deque() q.append((x, y)) while q: x, y = q.popleft() for i in range(4): nx, ny = x + dx[i], y + dy[i] if nx ..
2019. 10. 19.
[python] 5648. 원자 소멸 시뮬레이션
문제 출처 5648. 원자 소멸 시뮬레이션 풀이 tc = int(input()) for _ in range(tc): n = int(input()) atoms = [] mt, mr, mb, ml = 0, 0, 0, 0 for i in range(n): x, y, d, e = map(int, input().split()) if x > mr: mr = x if x mt: mt = y if y < mb: mb = y atoms.append([x*2, y*2, d, e]) mt *= 2 mr *= 2 mb *= 2 ml *= 2 direction = {0: (0, 1), 1: (0, -1), 2: (-1, 0), 3: (1, 0)} answer = 0 while atoms: c..
2019. 9. 6.
[python] 단어 변환
문제 출처 단어 변환 풀이 def dfs(now, target, words, history=[], depth=0): global min_ print(now, history) if now == target: min_ = min(min_, depth) if depth >= min_: return for word in words: if word in history: continue cnt = 0 for i in range(len(target)): if word[i] != now[i]: cnt += 1 if cnt > 1: break if cnt == 1 and word not in history: history.append(word) dfs(word, target, words, history, depth+1)..
2019. 9. 1.