일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 구현
- BFS
- 우선순위큐
- 자료구조
- 에라토스테네스의 체
- 분할정복
- 그리디
- GROUP BY
- join
- DFS
- 다시
- 다이나믹 프로그래밍
- 크루스칼
- 투포인터
- 백트래킹
- DP
- 다이나믹프로그래밍
- 브루트포스
- 재귀
- 누적합
- MST
- 시뮬레이션
- 해시
- 다익스트라
- 서브쿼리
- 그래프 탐색
- 플로이드-워셜
- 수학
- 그래프 이론
- 트리
- Today
- Total
목록우선순위큐 (4)
기록하고 까먹지 말기

날짜 : 2023. 10. 10 사용 언어 : python 문제 코드 import sys import heapq INF = int(1e20) def solution(operations): maxheap = list() minheap = list() hash = dict() cnt = 0 # 전체 큐에 남아있는 원소의 개수 for temp in operations: op, num = temp.split() num = int(num) if op == "I": # 삽입 cnt += 1 heapq.heappush(minheap, num) heapq.heappush(maxheap, num * (-1)) if num not in hash: hash[num] = 1 else: hash[num] += 1 continu..

날짜 : 2023. 10. 10 사용 언어 : python 문제 코드 import heapq INF = int(1e9) def solution(operations): maxheap = list() minheap = list() hash = dict() cnt = 0 # 전체 큐에 남아있는 원소의 개수 for temp in operations: op, num = temp.split() num = int(num) if op == "I": # 삽입 cnt += 1 heapq.heappush(minheap, num) heapq.heappush(maxheap, num * (-1)) if num not in hash: hash[num] = 1 else: hash[num] += 1 continue if cnt == ..

날짜 : 2023. 09. 24 사용 언어 : python 문제 코드 import sys import heapq n, m, x = map(int, sys.stdin.readline().split()) graph = [[] for _ in range(n + 1)] for _ in range(m): start, end, cost = map(int, sys.stdin.readline().split()) graph[start].append([end, cost]) INF = int(1e9) res = list() def dijkstra(start, end): dist = [INF] * (n + 1) # start 기준으로 거리 dist[start] = 0 # 본인 제외 queue = list() heapq.hea..

날짜 : 2023. 02. 15 사용 언어 : python 문제 코드 import sys import heapq n = int(sys.stdin.readline()) q = [] for i in range(n): x = int(sys.stdin.readline()) # 값 입력 if x != 0: heapq.heappush(q, (abs(x), x)) # 절댓값 기준으로 heapify, 쌍으로 저장 else: if len(q) == 0: # 힙이 비어있는 경우 print(0) else: # 비어있지 않은 경우 print(heapq.heappop(q)[1]) # 절댓값에 대응하는 값 출력 풀이 - 입력 시 (절댓값, 원본값) 쌍을 이루는 튜플을 만든 다음 절댓값을 기준으로 min heap을 구현한다. - ..