본문 바로가기
프로그래밍/문제풀이

[etc] 백준 1931 회의실 배정

by 하용권 2018. 12. 7.

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


종료시간으로 오름차순 정렬을 합니다.

만약 종료시간이 같은 경우에는 시작 시간이 더 빠른 것이 앞에 옵니다.




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
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    pair<int,int> p[100000];
    int N;
    
    cin >> N;
    
    for(int i = 0; i < N; i++)
        cin >> p[i].second>> p[i].first;
    
    sort(p,p+N);
    
    int cnt = 0;
    int end = 0;
    for(int i = 0; i < N; i++){
        if(end <= p[i].second){
            end = p[i].first;
            cnt++;
        }
    }
    
    cout << cnt;
}
 
 
cs


반응형

'프로그래밍 > 문제풀이' 카테고리의 다른 글

[etc] 백준 1946 신입 사원  (0) 2018.12.09
[etc] 백준 1049 기타줄  (0) 2018.12.07
[bfs] 백준 13460 구슬 탈출2  (0) 2018.11.28
[etc] 백준 13456 시험 감독  (0) 2018.11.26
[bfs] 백준 16234 인구 이동  (0) 2018.11.24