본문 바로가기

728x90

1. Programming/BaekJoon

(12)
[Baekjoon/Python] 1931번: 회의실 배정(Greedy) # Baekjoon 1931번: 회의실 배정 import sys input = sys.stdin.readline N = int(input()) room = [] for i in range(N): start, end = map(int, input().split()) room.append((start, end)) room = sorted(room, key = lambda x: x[0]) room = sorted(room, key = lambda x: x[1]) room_max = 0 present_end = 0 for s, e in room: if present_end 6, 10 으로 정렬이 되면 6, 10을 카운트하지 못하기에 고려해야 한다.
[Baekjoon/Python] 2178번: 미로 탐색(BFS) # Baekjoon 2178번: 미로 탐색 import sys from collections import deque input = sys.stdin.readline N, K = map(int, input().split()) maze = [[] for _ in range(N)] visited = [[] for _ in range(N+1)] for i in range(N): for j in range(K): visited[i].append(0) for i in range(N): maze_num = input() for j in maze_num: maze[i].append(j) def BFS(): visited[0][0] = 1 queue = deque() queue.append((0, 0)) while qu..
[Baekjoon/Python] 1697번: 숨바꼭질(BFS) # Baekjoon 1697번: 숨바꼭질 import sys from collections import deque input = sys.stdin.readline N, K = map(int, input().split()) visited = [0] * 2000002 def BFS(pos): queue = deque() queue.append(pos) visited[N] = 1 while queue: c = queue.popleft() if c == K: return visited[c]-1 for i in (c-1, c+1, 2*c): if visited[i] == 0 and 0
[Baekjoon/Python] 1541번: 잃어버린 괄호(Parshing) # Baekjoon 1541번: 잃어버린 괄호 import sys input = sys.stdin.readline equation = input().strip() token = [] num = "" for i in range(len(equation)): # 파싱 알고리즘 토큰화 if equation[i] == '-' or equation[i] == '+': token.append(equation[i]) else: num += equation[i] if i

728x90