思路不难,,
排序,查找,算是比较水的题了
代码如下:
#include <cstdio>
#include <cstring>
#include <cstdlib>
typedef struct{
int w, l;
}stick;
stick s[5050];
bool f[5050];
int comp(const void *a, const void *b)
{
stick *aa = (stick*)a, *bb = (stick*)b;
if(aa->l!=bb->l) return aa->l>bb->l;
return aa->w > bb->w;
}
int main ()
{
int n, cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
for(int i = 0; i < n; i++) scanf("%d%d",&s[i].l,&s[i].w);
qsort(s,n,sizeof(s[0]),comp);
int ans = 1, a = 0, b = 0, ok = 0;
memset(f,0,sizeof(f));
for(int i = 0; ok < n; i++)
{
if(i==n) {i = -1; a = 0; b = 0; ans++; continue; }
if(f[i]==false&&s[i].l>=a&&s[i].w>=b)
{ a = s[i].l; b = s[i].w; f[i] = true; ok++; }
}
printf("%d\n",ans);
}
return 0;
}