Poj1065

#include<stdio.h>
#include<stdlib.h>

struct g
{
	int l;
	int w;
	bool t;
}sticks[2505];

int cmp(const void *a,const void *b)
{
	struct g *c=(g *)a;
	struct g *d=(g *)b;
	if(c->l!=d->l)
		return c->l-d->l;
	else
		return c->w-d->w;
}

int main()
{
	int i,j,t,n;
	int ans,temp;

	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			sticks[i].t=false;
			scanf("%d%d",&sticks[i].l,&sticks[i].w);
		}
		qsort(sticks,n,sizeof(sticks[0]),cmp);
		ans=0;
		for(i=0;i<n;i++)
		{
			if(sticks[i].t==false)//未访问过
			{
				ans++;//随着i的变化,每一次把符合条件的都覆盖了
				temp=sticks[i].w;
				sticks[i].t=true;//
				for(j=i+1;j<n;j++)
				{
					if(sticks[j].t==false&&sticks[j].w>=temp)
					{
						sticks[j].t=true;
						temp=sticks[j].w;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

  个人还是有点不太理解为什么是:把L作为第一关键字,W作为第二关键字进行排序,然后再进行覆盖求ans就行。。。。

求指教。。。

posted @ 2012-07-12 13:01  xxx0624  阅读(1200)  评论(1编辑  收藏  举报