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 |
Tags
- 수학
- 유니티
- 알고리즘
- c++
- 백준
- 백트래킹
- DFS
- ue5
- 우선순위 큐
- 트리
- BFS
- 시뮬레이션
- 재귀
- XR Interaction Toolkit
- 구현
- 투 포인터
- 누적 합
- Unreal Engine 5
- Team Fortress 2
- 스택
- VR
- 정렬
- 문자열
- 다익스트라
- 브루트포스
- 그리디 알고리즘
- 유니온 파인드
- 다이나믹 프로그래밍
- 그래프
- 자료구조
Archives
- Today
- Total
1일1알
백준 26215번 눈 치우기 C++ 본문
https://www.acmicpc.net/problem/26215
26215번: 눈 치우기
집 2와 집 3 앞의 눈을 치우고, 집 2와 집 3 앞의 눈을 치우고, 집 1과 집 3 앞의 눈을 치운 뒤 집 3 앞의 눈을 두 번 치우면 5분만에 모든 집 앞의 눈을 치울 수 있다.
www.acmicpc.net
우선순위 큐를 사용해서 눈이 많이 쌓인 집부터 치움
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
priority_queue<int> pq;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
pq.push(a);
}
int ans = 0;
while (!pq.empty()) {
int a = pq.top();
pq.pop();
a -= 1;
if (pq.empty() == false) {
int b = pq.top();
pq.pop();
b -= 1;
if (b > 0) pq.push(b);
}
if (a > 0) pq.push(a);
ans++;
}
if (ans > 1440) ans = -1;
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 2866번 문자열 잘라내기 C++ (0) | 2023.01.20 |
---|---|
백준 1138번 한 줄로 서기 C++ (0) | 2023.01.19 |
백준 14940번 쉬운 최단거리 C++ (0) | 2023.01.17 |
백준 2823번 유턴 싫어 C++ (1) | 2023.01.16 |
백준 20310번 타노스 C++ (0) | 2023.01.15 |