#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
struct Edg
{
int l, r;
}edg[N];
bool cmp(Edg a, Edg b)
{
if (a.l != b.l) return a.l < b.l;
else return a.r < b.r;
}
int res;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i ++ )
{
cin >> edg[i].l >> edg[i].r;
}
sort(edg, edg + n, cmp);
int st = -2e9, ed = -2e9;
for (int i = 0; i < n; i ++ )
{
if (edg[i].l >= ed)
{
st = edg[i].l;
ed = edg[i].r;
res ++ ;
}
else
{
ed = min(ed, edg[i].r);
}
}
cout << res << endl;
return 0;
}
以第1个活动时间开始
#include <bits/stdc++.h>
// #define int long long
#define LL long long
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 1010;
int n;
struct E
{
int l, r;
bool operator< (const E& w) const
{
return l < w.l;
}
}e[N];
signed main()
{
IOS;
cin >> n;
for (int i = 1; i <= n; i ++ )
{
cin >> e[i].l >> e[i].r;
}
sort(e + 1, e + n + 1);
int res = 0;
int st = e[1].l, ed = e[1].r;
for (int i = 2; i <= n; i ++ )
{
if (e[i].l >= ed)
{
st = e[i].l, ed = e[i].r;
res ++ ;
}
else
{
ed = min(ed, e[i].r);
}
}
cout << res + 1 << endl;
return 0;
}