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 49 | #include <stdio.h> #include <utility> #include <vector> #include <algorithm> using namespace std; typedef long long ll; vector<pair<ll, ll> > arr(200000); bool compare(const pair<ll,ll>& a, const pair<ll,ll>& b) { if (a.second == b.second) { if (a.first < b.first) return true; else return false; } else { if (a.second < b.second) return true; else return false; } } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { ll a, b; scanf("%lld %lld", &a, &b); arr[i].first = a; arr[i].second = b; } // sort 할때 참조 범위 주의 sort(&arr[1], &arr[n+1], compare); pair<int, int> st; ll tmp = 0; for (int i = 1; i <= n; i++) { if (st.second <= arr[i].first) { st = make_pair(arr[i].first, arr[i].second); tmp++; } } printf("%lld", tmp); } | cs |
'알고리즘 > 그리디 알고리즘' 카테고리의 다른 글
mixing milk 더블릿 (0) | 2019.02.20 |
---|---|
(복습필요) 11000 강의실 배정 (0) | 2019.02.19 |
11047 동전만들기 (0) | 2019.02.19 |
1449 수리공 항승 (0) | 2019.02.19 |
4796 캠핑 (0) | 2019.02.19 |