일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- permutation
- Combination
- LCS
- 1182
- 11기
- expo
- itertools
- 최소공배수
- 11054
- 1260
- 매일11시
- 11057
- 앱
- 6603
- 홈화면
- lcm
- Kotlin
- Python
- 11053
- Android
- 코테
- 괄호
- 나머지
- 뒤로가기
- 안드로이드
- 백준
- 9095
- 코틀린
- 파이썬
- 순열
Archives
- Today
- Total
목록11279 (1)
황소개발자
백준 11279 파이썬 python : 최대 힙 @@황소처럼 우직하게@@ heapq 사용
파이썬의 heapq 는 기본이 minheap 입니다. 이걸 어떻게 maxheap 으로 이용할 것이냐? import sys import heapq input = sys.stdin.readline n = int(input().strip()) q = [] for i in range(n): num = int(input().strip()) if num == 0: if q: print(-heapq.heappop(q)) else: print(0) else: heapq.heappush(q, -num) -num 으로 해서 음수로 바꿔서 넣어주고 꺼낼때 - 붙여서 꺼내주면 됩니다.
백준 문제 풀이
2020. 4. 21. 13:50