[파이썬/python] 백준 1795 - 마알
·
Algorithm
import sys, math from collections import deque dx = [1, 1, -1, -1, 2, -2, 2, -2] dy = [2, -2, 2, -2, 1, 1, -1, -1] path = [] N, M = map(int, sys.stdin.readline().split()) for i in range(N): temp = sys.stdin.readline().rstrip() temp_arr = [] for j, each in enumerate(temp): if each == '.': temp_arr.append(0) else: temp_arr.append(int(each)) path.append(temp_arr) deq = deque() def bfs(x, y): deq.ap..
[파이썬/python] 백준 1012번 - 유기농 배추
·
Algorithm
import sys T = int(sys.stdin.readline()) cnt = 0 ans = [] # dfs def dfs(y, x): arr[y][x] = 0 if y + 1 = 0: if arr[y-1][x] == 1: dfs(y-1, x) if x + 1 = 0: if arr[y][x-1] == 1: dfs(y, x-1) for i in range(T): N, M, K = map(int, sys.stdin.readline().split()) arr = [[0 for j in range(M)] for i in range(N)]..
[파이썬/python] 백준 1260번 - DFS와 BFS
·
Algorithm
import sys # DFS ansDFS = list() def dfs(curr, val): if val in ansDFS: return ansDFS.append(val) for i in curr[]: dfs(edges[i-1], i) # BFS ansBFS = list() queue = list() def bfs(curr, val): if val in ansBFS: return ansBFS.append(val) for i in curr[]: queue.append(i) while len(queue) != 0: temp = queue.pop(0) bfs(edges[temp-1], temp) N, M, V = map(int, sys.stdin.readline().split()) edges = list()..
[파이썬/python] 백준 1863번 스카이라인 쉬운거
·
Algorithm
import sys from collections import Counter N = int(sys.stdin.readline()) skyline = list() for i in range(N): A, B = map(int, sys.stdin.readline().split()) tup = (A, B) tup = list(tup) skyline.append(tup) count = 0 index = 1 # 사실 지금 생각해보니 튜플로 저장할 필요가 없음 # x좌표는 어차피 순서대로 입력돼서 필요 없는데 왜 저장했지 # 아무튼 바꾸기 귀찮으니까 걍 커밋함 for i in skyline: if i[1] == 0: index += 1 continue if i == skyline[N - 1]: count += 1 b..
[파이썬/python] 백준 1374번 강의실
·
Algorithm
import sys N = int(sys.stdin.readline()) lec = list() for i in range(N): num, start, finish = map(int, sys.stdin.readline().split()) lec.append([start, finish]) lec.sort() temp = [lec[0][1]] index = 1 minFinish = temp[0] while index lec[index][1]: minFinish = lec[index][1] else: temp.sort() temp[0] = lec[index][1]..
[파이썬/python] 백준 1101번 카드 정리 1
·
Algorithm
N, M = map(int, input().split()) box = list() for i in range(N): box.append(list(map(int, input().split()))) jocker = list() one = list() for b in box: already = False isOne = -1 for index in range(M): if b[index] != 0: # check non-zeros if not already: already = True isOne = index else: # two non-zeros exist if isOne != -1: jocker.append(b) # add to jocker isOne = -1 if isOne != -1: one.append(..
Sean 션
'Algorithm' 카테고리의 글 목록