/***********
Author Smile
区间重叠问题,贪心 + 双指针(类似)
https://vjudge.csgrandeur.cn/contest/477345#problem/C
***********/
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1E3 + 10;
int n;
int ans = 1;
struct node
{
int si, fi;
}region[N];
bool comp(node a, node b)
{
return a.fi < b.fi;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> region[i].si >> region[i].fi;
}
sort(region + 1, region + 1 + n, comp);
int cnt;
for (int i = 1; i <= n; i = cnt)
{
for (int j = i + 1; j <= n; ++j)
{
if (region[i].fi <= region[j].si)
{
ans++;
cnt = j;
break;
}
if (j == n)
cnt = j + 1;
}
}
cout << ans << endl;
return 0;
}
|