본문 바로가기

구현12

[백준] 17472번 - 다리 만들기 2 (파이썬) # 다리 만들기 2 from collections import deque import sys input = sys.stdin.readline MAX = sys.maxsize dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] N, M = map(int, input().split()) land = [] arr = [] for i in range(N): arr.append(list(map(int, input().split()))) for j in range(M): if arr[i][j] == 1: land.append((i, j)) def find_land(visited, a, b, num): q = deque() q.append((a, b)) while q: x, y = q.popleft(.. 2022. 2. 19.
[백준] 17143번 - 낚시왕 (파이썬) # 낚시왕 import copy import sys input = sys.stdin.readline N, M, S = map(int, input().split()) arr = [[0] * (M+1) for _ in range(N+1)] for _ in range(S): n, m, speed, direction, big = map(int, input().split()) arr[n][m] = (speed, direction, big) shark_move = [[], [-1, 0], [1, 0], [0, 1], [0, -1]] def fishing(now): global result for i in range(1, N+1): if arr[i][now] != 0: result += arr[i][now][2] a.. 2022. 2. 11.
[백준] 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.
[백준] 14890번 - 경사로 (파이썬) # 경사로 import sys input = sys.stdin.readline N, L = map(int, input().split()) arr = [] for _ in range(N): arr.append(list(map(int, input().split()))) result = 0 def check(line): global result isOK = True isSlope = [False] * N for i in range(N-1): if line[i] == line[i+1]: continue elif abs(line[i] - line[i+1]) >= 2: isOK = False break elif abs(line[i] - line[i+1]) == 1: if slope_check(line, i, isS.. 2022. 1. 26.
[백준] 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.