• 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就行。。。。

    求指教。。。

    keep moving...
  • 相关阅读:
    静态构造函数
    js-----Date对象
    JS中Math函数的常用方法
    js 简单数据类型和复杂数据类型的区别
    js new关键字 和 this详解
    JS 对象的三种创建方式
    js 预解析
    JS作用域问题
    js实现斐波那契数列
    JS 三元表达式
  • 原文地址:https://www.cnblogs.com/xxx0624/p/2587911.html
Copyright © 2020-2023  润新知