본문 바로가기
백준

C++ 1931 회의실 배정

by 안선생 2023. 2. 10.
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
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;
 
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
 
    int n; cin >> n;
    vector<pair<intint>> a;
 
    while (n--)
    {
        int b, e;
        cin >> b >> e;
        a.push_back(make_pair(e, b)); //끝난 시간 기준으로 넣어준다.
    }
    sort ( a.begin(), a.end()); // 정렬
    int time = a[0].first;
    int cnt = 1;
    for (int i = 1; i < a.size(); i++)
    {
        if (time <= a[i].second) // 첫번째 끝난시간이 다음 회의에 시작시간보다 크거나 같은경우
        {
            time = a[i].first; // 다음회의 끝난시간으로 바꿔준다.
            cnt++;
        }
    }
    cout << cnt;
    return 0;
 
}
 
 
cs

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

 

1931번: 회의실 배정

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

www.acmicpc.net

 

'백준' 카테고리의 다른 글

C++ 1439 뒤집기  (0) 2023.02.11
C++ 5585 거스롬돈  (0) 2023.02.11
C++ 13305 주요소  (0) 2023.02.10
C++ 13305 잃어버린 괄호  (0) 2023.02.10
C++ 11399 ATM  (0) 2023.02.10