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
- 누적 합
- ue5
- 자료구조
- 유니티
- 백준
- DFS
- 정렬
- 투 포인터
- c++
- 스택
- BFS
- 그래프
- 브루트포스
- 수학
- 우선순위 큐
- 백트래킹
- 알고리즘
- Team Fortress 2
- Unreal Engine 5
- 그리디 알고리즘
- 트리
- XR Interaction Toolkit
- 다익스트라
- 시뮬레이션
- 문자열
- VR
- 구현
- 유니온 파인드
- 다이나믹 프로그래밍
- 재귀
Archives
- Today
- Total
1일1알
백준 14241번 슬라임 합치기 C++ 본문
https://www.acmicpc.net/problem/14241
14241번: 슬라임 합치기
영선이와 효빈이는 슬라임을 합치는 게임을 하고 있다. 두 사람은 두 슬라임을 골라서 하나로 합쳐야 한다. 게임은 슬라임이 하나 남았을 때 끝난다. 모든 슬라임은 양수 크기를 가지고 있다. 두
www.acmicpc.net
우선순위 큐
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
using namespace std;
int main()
{
int n;
cin >> n;
priority_queue<int> pq;
for (int i = 0; i < n; i++) {
int input;
cin >> input;
pq.push(input);
}
int score = 0;
while (!pq.empty()) {
if (pq.size() == 1) break;
int a = pq.top();
pq.pop();
int b = pq.top();
pq.pop();
score += a * b;
pq.push(a + b);
}
cout << score;
}
'알고리즘' 카테고리의 다른 글
백준 13164번 행복 유치원 C++ (0) | 2022.11.12 |
---|---|
백준 1956번 운동 C++ (0) | 2022.11.11 |
백준 11060번 점프 점프 C++ (0) | 2022.11.07 |
백준 20311번 화학 실험 C++ (0) | 2022.11.05 |
백준 23351번 물 주기 C++ (0) | 2022.11.04 |