使用C++ 类
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100010;
int res;
class range {
public:
int l, r;
range(int left = 0, int right = 0) : l(left), r(right) {}
bool operator<(const range &A)
{
return r < A.r;
}
void init(int left, int right)
{
l = left;
r = right;
}
};
range rec[N];
int main ()
{
int n, l, r;
scanf ("%d", &n);
for (int i = 0; i < n; i ++)
{
scanf("%d%d", &l, &r);
rec[i].init(l, r);
}
sort (rec, rec + n);
int ed = -2e9;
for (int i = 0; i < n; i ++)
{
if (rec[i].l > ed)
{
res ++;
ed = rec[i].r;
}
}
printf("%d", res);
return 0;
}