总感觉算是模拟一类的题型,一步一步往下写,没有漏洞就行了。
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node
{
int a,b;
}p[100008];
bool cmp(node p,node q)
{
if(q.b == p.b) return (p.a < q.a);
else return (p.b < q.b);
}
int main()
{
int N;scanf("%d",&N);
for(int i = 0;i < N;i ++)
scanf("%d %d",&p[i].a,&p[i].b);
sort(p,p + N,cmp);
int ans = 1,j = 0;
for(int i = 1;i < N;i ++){
if(p[i].a - 1 >= p[j].b){
j = i;
ans ++;
}
}
printf("%d\n",ans);
return 0;
}