나의 브을로오그으

[c++] 1931번 : 회의실 배정 본문

알고리즘/BaekJoon

[c++] 1931번 : 회의실 배정

__jhp_+ 2022. 6. 22. 15:53

https://www.acmicpc.net/problem/1931

 

1931번: 회의실 배정

(1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다.

www.acmicpc.net

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	vector<pair<int, int>> v;
	int N = 0, from = 0, to = 0;
	cin >> N;
	v.reserve(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> from >> to;
		v.push_back(make_pair(to, from));
	}
	sort(v.begin(), v.end());

	int earliest = 0, count = 0, begin = 0, end = 0;
	for (size_t i = 0; i < v.size(); ++i)
	{
		begin = v[i].second;
		end = v[i].first;
		if (earliest <= begin)
		{
			earliest = end;
			++count;
		}
	}
	cout << count << '\n';
	return 0;
}

'알고리즘 > BaekJoon' 카테고리의 다른 글

[c++] 2178번 : 미로 탐색  (0) 2022.06.23
[c++] 1992번 : 쿼드트리  (0) 2022.06.23
[c++] 1927번 : 최소 힙  (0) 2022.06.21
[c++] 1764번 : 듣보잡  (0) 2022.06.15
[c++] 1697번 : 숨바꼭질  (0) 2022.06.14