<< 문제 >>
https://www.acmicpc.net/problem/1931
<< 풀이 >>
일단, 끝나는 시간을 먼저 고려했습니다.
시작 시간이 어떻든 끝나는 시간이 중요한거니,
끝나는 시간으로 정렬한 후 시작 시간이 이전에 고려한 끝나는 시간보다 이후인지만 생각하면 됩니다.
<< 코드 >>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
priority_queue<vector<int>> timeTables;
for (int i = 0; i < n; i++)
{
int start, end;
vector<int> timeTable;
cin >> start >> end;
// 끝나는 시간, 시작 시간
timeTable.push_back(-end);
timeTable.push_back(-start);
timeTables.push(timeTable);
}
int cnt = 0;
int lastTime = 0; // 마지막 끝난 시간
while (!timeTables.empty())
{
if (-timeTables.top()[1] >= lastTime)
{
cnt++;
lastTime = -timeTables.top()[0];
timeTables.pop();
}
else {
timeTables.pop();
}
}
cout << cnt;
}
<< GitHub >>
StudyAlgorithm_Part2/백준/Silver/1931. 회의실 배정 at main · J2on/StudyAlgorithm_Part2
This is a auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - J2on/StudyAlgorithm_Part2
github.com
< 백준 BaekJoon : 1026번 보물 > C++ (0) | 2024.06.20 |
---|---|
< 백준 BaekJoon : 17520번 Balanced String > C++ (0) | 2024.06.20 |
< 백준 BaekJoon : 20058번 마법사 상어와 파이어스톰 > C++ (0) | 2024.04.09 |
< 백준 BaekJoon : 2457번 공주님의 정원 > C++ (0) | 2024.04.01 |
< 백준 BaekJoon : 16953번 A → B > C++ (0) | 2024.03.30 |
댓글 영역