#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int T;
int n;
typedef struct
{
int l;
int w;
}stick;
int cmp(stick a,stick b) //这个函数写错了很多次,坑的一笔,找个时间要好好看看
{
if(a.l == b.l)
{
return a.w < b.w;
}
else
{
return a.l < b.l;
}
}
stick sticks[5000];
int mark[5000]; //用来标记是否已经形成了一个递增序列
int main()
{
cin>>T;
while(T--)
{
cin>>n;
for(int i = 0; i < n; i++)
{
cin>>sticks[i].l>>sticks[i].w;
}
memset(mark,0,sizeof(mark));
sort(sticks,sticks+n,cmp); //排序
stick p;
int minute = 1; //刚开始要1分钟
for(int i = 0; i < n; i ++)
{
if(mark[i] == 1) //如果已经形成一个序列
{
mark[i] = 1;
continue;
}
mark[i] = 1; //放入当前递增序列中
minute++;
p = sticks[i];
for(int j = i+1; j < n;j++)//贪心构建递增序列
{
if(mark[j]==0 && sticks[j].l >= p.l && sticks[j].w >= p.w)
{
mark[j] = 1;
p = sticks[j];
}
}
}
cout<<minute-1<<endl;
}
return 0;
}
hdu1051贪心
最新推荐文章于 2022-11-13 20:15:43 发布

877

被折叠的 条评论
为什么被折叠?



