分析:排序后,从小找到大,注意保存第一个不满足条件的stick,作为第二次查找的开始
#include<iostream>
#include<algorithm>
using namespace std;
const int NM=5005;
struct Stick{
int x,y;
}st[NM];
bool comp(struct Stick A,struct Stick B)
{
if(A.x<B.x) return 1;
else
{
if(A.x==B.x)
{
if(A.y<B.y) return 1;
else return 0;
}
else return 0;
}
}
int main()
{
int sx,sy,ex,ey,time,n,i,T,ans;
cin>>T;
while(T--)
{
cin>>n;
for(i=0;i<n;i++)
cin>>st[i].x>>st[i].y;
if(n==1) {cout<<1<<endl;continue;}
sort(st,st+n,comp);
ex=st[0].x,ey=st[0].y;
ans=1;
time=0;
while(ans<n)
{
time++;
sx=ex,sy=ey;
ex=ey=1000000;
for(i=1;i<n;i++)
{
if(st[i].x>0&&st[i].x>=sx&&st[i].y>=sy)
{
sx=st[i].x,sy=st[i].y;
st[i].x=0,st[i].y=0;
ans++;
}
else
{
if(st[i].x<ex)
ex=st[i].x,ey=st[i].y;
}
}
}
cout<<time<<endl;
}
return 0;
}