LibreOJ #10000. 「一本通 1.1 例 1」活动安排

Description:

选若干个区间,使得两两不重合,求最大的区间个数

Code

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
pair<int, int> itv[1100];
int n;
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", &itv[i].second, &itv[i].first);
    }
    sort(itv, itv + n);
    int ans = 0, ed = -1;
    for (int i = 0; i < n; ++i) {
        if (ed <= itv[i].second) {
            ans++;
            ed = itv[i].first;
        }
    }
    printf("%d", ans);
    return 0;
}
posted @ 2019-08-01 17:28  Zforw  阅读(72)  评论(0编辑  收藏  举报