[백준] 15685번 - 드래곤 커브 (파이썬)
# 드래곤 커브 import sys input = sys.stdin.readline T = int(input()) arr = [[False] * 101 for _ in range(101)] dx = [0, -1, 0, 1] dy = [1, 0, -1, 0] q = [] for _ in range(T): y, x, d, g = map(int, input().split()) q.append((x, y, d, g)) def dragon_curve(): for x, y, d, g in q: arr[x][y] = True dir = [d] for _ in range(g): for d in range(len(dir)-1, -1, -1): temp = (dir[d] + 1) % 4 dir.append(temp) fo..
2022. 1. 26.
[백준] 2573번 - 빙산 (파이썬)
# 빙산 from collections import deque import sys input = sys.stdin.readline N, M = map(int, input().split()) arr = [] ice = [] melt = [] for i in range(N): arr.append(list(map(int, input().split()))) for j in range(M): if arr[i][j] != 0: ice.append((i, j)) dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def melt_check(): for x, y in ice: if arr[x][y] != 0: zero = 0 for k in range(4): nx = x + dx[k] ny = y + ..
2022. 1. 25.
[백준] 1238번 - 파티 (파이썬)
# 파티 import sys import heapq input = sys.stdin.readline MAX = sys.maxsize N, M, X = map(int, input().split()) arr = [[] for _ in range(N+1)] for _ in range(M): a, b, cost = map(int, input().split()) arr[a].append((cost, b)) come = [MAX] * (N+1) go = [MAX] * (N+1) def go_dijkstra(x): q = [] heapq.heappush(q, (0, x)) go[x] = 0 while q: cost, node = heapq.heappop(q) for ncost, nnode in arr[node]: i..
2022. 1. 25.
[백준] 12100번 - 2048(Easy) (파이썬)
# 2048 (Easy) import copy import sys input = sys.stdin.readline N = int(input()) arr = [] for _ in range(N): arr.append(list(map(int, input().split()))) dir = [[0, 1], [1, 0], [0, -1], [-1, 0]] result = 0 def move_block(arr, n): set_result(arr) if n == 5: # 이동 끝 return for k in range(4): temp = copy.deepcopy(arr) combine_and_move(temp, k) move_block(temp, n+1) def combine_and_move(arr, k): is_co..
2022. 1. 25.