본문 바로가기
알고리즘/그리디 알고리즘

테이블 옮기기 더블릿

by tryotto 2019. 2. 20.
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
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>
#include <queue>
 
using namespace std;
vector<pair<intint> > table(300);
priority_queue<intvector<int>, greater<int> > pq;
 
bool compare(const pair<intint>& a, const pair<intint>& b) {
    if (a.first == b.first)
        return a.second < b.second;
    return a.first < b.first;
}
 
int main() {
    int n;
    scanf("%d"&n);
 
    for (int i = 1; i <= n; i++) {
        int a, b;
        scanf("%d %d"&a, &b);
// a,b 크기가 반대일 수도 있다. 스왑 해주자
        if (a > b) swap(a, b);
 
        if (a % 2 == 0) a--;
        if (b % 2 == 1) b++;
        table[i].first = a;
        table[i].second = b;
    }
    sort(&table[1], &table[n + 1], compare);
// 11000번 강의실 백준 
    pq.push(table[1].second);
    for (int i = 2; i <= n; i++) {
        int start = table[i].first;
        int end = table[i].second;
        if (pq.top() <= start) {
            pq.pop();
            pq.push(end);
        }
        else {
            pq.push(end);
        }
    }
    printf("%d"10 * pq.size());
}
cs


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

5585 거스름돈  (0) 2019.06.22
11399 ATM  (0) 2019.06.22
마감시간을 가지는 작업 더블릿  (0) 2019.02.20
knapsack 더블릿  (0) 2019.02.20
mixing milk 더블릿  (0) 2019.02.20