2486: 【普及-】【P1803】 凌乱的yyy / 线段覆盖

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:24 解决:10

题目描述

现在各大 oj 上有 lns="http://www.w3.org/1998/Math/MathML"> 个比赛,每个比赛的开始、结束的时间点是知道的。

yyy 认为,参加越多的比赛,noip 就能考的越好(假的)。

所以,他想知道他最多能参加几个比赛。

由于 yyy 是蒟蒻,如果要参加一个比赛必须善始善终,而且不能同时参加 lns="http://www.w3.org/1998/Math/MathML">2 个及以上的比赛。

输入

第一行是一个整数 lns="http://www.w3.org/1998/Math/MathML"> ,接下来 lns="http://www.w3.org/1998/Math/MathML"> 行每行是 lns="http://www.w3.org/1998/Math/MathML">2 个整数 lns="http://www.w3.org/1998/Math/MathML">, ( lns="http://www.w3.org/1998/Math/MathML">< ),表示比赛开始、结束的时间。

输出

一个整数最多参加的比赛数目。

样例输入 复制

3
0 2
2 4
1 3

样例输出 复制

2

提示

对于 lns="http://www.w3.org/1998/Math/MathML">20% 的数据, lns="http://www.w3.org/1998/Math/MathML">10

对于 lns="http://www.w3.org/1998/Math/MathML">50% 的数据, lns="http://www.w3.org/1998/Math/MathML">103

对于 lns="http://www.w3.org/1998/Math/MathML">70% 的数据, lns="http://www.w3.org/1998/Math/MathML">105

对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据, lns="http://www.w3.org/1998/Math/MathML">1106 , lns="http://www.w3.org/1998/Math/MathML">0<106


#include<bits/stdc++.h>
using namespace std;
int n, ans = 0, finish = 0;
struct contest {
    int l, r;
} con[1000010];
bool cmp(contest a, contest b) {
    return a.r <= b.r;
}
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> con[i].l >> con[i].r; 
    sort(con + 1, con + 1 + n, cmp);
    for (int i = 1; i <= n; i++)
        if (finish <= con[i].l)
            ans++, finish = con[i].r;
    cout << ans << endl;
    return 0;
}