관리 메뉴

민우의 코딩노트

백준 1931번: 회의실 배정 - C++ 본문

Algorithm/BOJ

백준 1931번: 회의실 배정 - C++

미미누 2022. 2. 26. 03:30

[문제]

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

 

1931번: 회의실 배정

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

www.acmicpc.net

 

[풀이]

그리디 알고리즘

 

[코드]

#include <bits/stdc++.h>
using namespace std;

int n;
pair<int, int> s[100005];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> s[i].second >> s[i].first;
    }
    sort(s, s+n);
    
    int ans=0;
    int t=0;
    for(int i=0; i<n; i++){
        if(t > s[i].second) continue;
        ans++;
        t = s[i].first;
    }
    cout << ans;
}

 

'Algorithm > BOJ' 카테고리의 다른 글

백준 3273번 - 두 수의 합 C++  (0) 2022.04.16
백준 1475번 - C++ 방 번호  (0) 2022.04.14
백준 2217번: 로프 - C++  (0) 2022.02.26
백준 1026번: 보물 - C++  (0) 2022.02.26
백준 11659번 구간 합 구하기 4 - C++  (0) 2022.02.16