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
- 누적 합
- 구현
- 투 포인터
- Unreal Engine 5
- Team Fortress 2
- 시뮬레이션
- 다이나믹 프로그래밍
- ue5
- 알고리즘
- 재귀
- 백트래킹
- 자료구조
- 그리디 알고리즘
- 스택
- 문자열
- 우선순위 큐
- 트리
- c++
- 유니온 파인드
- DFS
- 그래프
- 수학
- BFS
- 다익스트라
- 유니티
- 브루트포스
- VR
- 정렬
- XR Interaction Toolkit
- 백준
Archives
- Today
- Total
1일1알
백준 19640번 화장실의 규칙 C++ 본문
https://www.acmicpc.net/problem/19640
19640번: 화장실의 규칙
위와 같이 줄을 선 경우를 생각해보자. (x, y) 는 사원의 근무 일수가 x, 화장실이 급한 정도가 y임을 나타낸다. [x, y]는 해당 사원이 데카임을 의미한다. 즉, 위의 그림에서 데카는 3번 사원이다.
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;
struct Info {
int d;
int h;
int line;
bool deka;
bool operator<(const Info& other) const {
if (d != other.d) return d < other.d;
if (h != other.h) return h < other.h;
return line > other.line;
}
};
int n, m, k;
vector<queue<Info>> v;
priority_queue<Info> pq;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m >> k;
v = vector<queue<Info>>(m);
for (int i = 0; i < n; i++) {
int line = i % m;
int d, h;
bool deka = i == k;
cin >> d >> h;
Info info{ d,h,line,deka };
v[line].push(info);
}
for (auto a : v) {
if (a.empty()) continue;
pq.push(a.front());
}
int ans = 0;
while (true) {
auto curr = pq.top();
if (curr.deka) break;
pq.pop();
ans++;
int line = curr.line;
v[line].pop();
if (v[line].empty() == false) {
pq.push(v[line].front());
}
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 12845번 모두의 마블 C++ (0) | 2022.12.27 |
---|---|
백준 15558번 점프 게임 C++ (0) | 2022.12.25 |
백준 20920번 영단어 암기는 괴로워 C++ (0) | 2022.12.23 |
백준 16924번 십자가 찾기 C++ (0) | 2022.12.22 |
백준 2072번 오목 C++ (0) | 2022.12.21 |