最悲哀的,莫过于死活不过...
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
#define N 5005
class node
{
public:
int left,right;
};
node st[N];
int n;
int cmp(const void *a,const void *b)
{
node *c =(node *)a;
node *d =(node *)b;
if(c->left >d->left ) return 1;
if(c->left ==d->left &&c->right >d->right ) return 1;
return 0;
}
//void work()
//{
// int i,j,k;
// int ans =0;
// int ts=1,ed=1;
// for(i=0;ed<=n;)
// {
// bool flag=false;
// while(st[i].left<=ts&&st[i].right>=ed)
// {
// flag=true;
// ed =st[i].right;i++;
// if(i>=n) break;
// }
// if(flag&&ed==n) { printf("%d\n",++ans);return ;}
// if(flag) {ans++; ed+=1;ts=ed;}
// while(st[i].right <ed&&i<n) i++;
// }
// printf("%d\n",ans);
//}
int work()
{
int minp=1,maxp=n;
int cur=minp;
int i=0,sum=0;
while(cur<=maxp&&i<n)
{
int temp =cur;
while(st[i].left <=cur)
{
if(temp<st[i].right ) temp =st[i].right ;
i++;
}
cur=temp+1;sum++;
}
return sum;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&st[i].left ,&st[i].right );
if(st[i].right >n) st[i].right =n;
}
qsort(st,n,sizeof(st[0]),cmp);
printf("%d\n",work());
}
return 0;
}