[백준 11286] 절댓값 힙 - Python import sys,heapq input = sys.stdin.readline n = int(input()) heap = [] for _ in range(n): num = int(input()) if num==0: if len(heap)==0: print(0) else: min = heapq.heappop(heap)[1] print(min) else: heapq.heappush(heap,(abs(num),num)) 취준시절/백준 2021.08.01
[백준 1927] 최소 힙 - Python import heapq import sys input = sys.stdin.readline n = int(input()) heap = [] for _ in range(n): num = int(input()) if num == 0: if len(heap)==0: print(0) else: min = heapq.heappop(heap) print(min) else: heapq.heappush(heap,num) 취준시절/백준 2021.08.01
[백준 2164] 카드2 - Python from collections import deque import sys input = sys.stdin.readline n = int(input()) queue = deque(i for i in range(1,n+1)) if len(queue)==1: print(queue[0]) else: first = queue.popleft() while len(queue)>1: first = queue.popleft() queue.append(first) queue.popleft() print(queue[0]) 취준시절/백준 2021.07.31
[백준 1158] 요세푸스 문제 - Python from collections import deque # 요세푸스 순열 import sys input = sys.stdin.readline n,k = map(int,input().split()) queue = deque([i for i in range(1,n+1)]) result = list() cnt = 0 while len(result) 취준시절/백준 2021.07.31
[백준 1966] 프린터 큐- Python from collections import deque import sys input = sys.stdin.readline testcase = int(input()) result = list() for _ in range(testcase): n,m = map(int,input().split()) queue = deque(map(int,input().split())) idx = deque(i for i in range(n)) cnt = 0 max_num = max(queue) while True: first = queue.popleft() first_idx = idx.popleft() if first_idx == m and first==max_num: cnt+=1 result.append(cnt) break.. 취준시절/백준 2021.07.31