Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 오퍼레이팅시스템
- 코테
- 알고리즘
- 오에스
- 문제풀이
- 너비우선탐색
- 개발
- 컴공
- OS
- 컴공과
- 코딩
- vector
- 컴퓨터공학과
- DP
- 북리뷰
- coding
- 스택
- 브루트포스
- 자료구조
- 그래프
- Operating System
- c++
- Computer science
- 백준
- 정석
- cs
- Stack
- bfs
- 정석학술정보관
- 구현
Archives
- Today
- Total
Little Jay
[C++] 백준 1655번 - 가운데를 말해요 본문
while문의 조건을 짜는게 많이 까다로웠던 문제
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int N;
priority_queue<int, vector<int>, greater<int>> min_heap;
priority_queue<int, vector<int>, less<int>> max_heap;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N;
while(N--) {
int score;
cin >> score;
if (min_heap.empty() || max_heap.empty()) {
max_heap.push(score);
}
else {
if (score <= max_heap.top())
max_heap.push(score);
else if (score >= min_heap.top())
min_heap.push(score);
else
max_heap.push(score);
}
while (!(max_heap.size() == min_heap.size() || max_heap.size() == min_heap.size() + 1 )) {
if (max_heap.size() > min_heap.size()) {
min_heap.push(max_heap.top());
max_heap.pop();
}
else {
max_heap.push(min_heap.top());
min_heap.pop();
}
}
cout << max_heap.top() << endl;
}
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 14464번 - 소가 길을 건너간 이유 4 (0) | 2022.04.27 |
|---|---|
| [C++] 백준 6679번 - 싱기한 네자리 숫자 (0) | 2022.03.20 |
| [C++]백준 5014번 - 면접에 늦었다 (0) | 2022.03.14 |
| [C++] 백준 11055번 - 가장 큰 증가 부분 수열 (0) | 2022.02.21 |
| [C++] 백준 9461번 - 파도반 수열 (0) | 2022.02.21 |
Comments