zoukankan      html  css  js  c++  java
  • HDOJ:1051

    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #define K  5001
    using namespace std;
    
    struct st
    {
    	int l;
    	int w;
    	bool t;
    }a[K]; 
    
    bool cmp(st a,st b)
    {
    	if(a.l==b.l)
    		return a.w>b.w;
    	else
    		return a.l>b.l;
    }
    
    int main(void)
    {
    	freopen("in.txt","r",stdin);
    	int N;
    	scanf("%d",&N);
    	while(N--)
    	{
    		int n,i;
    		scanf("%d",&n);
    		
    		for(i=0;i<n;i++)
    			scanf("%d%d",&a[i].l,&a[i].w);
    			
    		sort(a,a+n,cmp);
    		int l0,w0,s=0,sign=0,m=0;
    		while(sign!=n)
    		{ 
    			for(i=m;i<n;i++)
    				if(a[i].t==false)
    				{
    					l0=a[i].l;
    					w0=a[i].w;
    					a[i].t==true;
    					s++;
    					i++;
    					sign++;
    					m=i;
    					break;
    				}
    			for(;i<n;i++)
    				if(a[i].t==false&&a[i].w<=w0)
    				{
    					l0=a[i].l;
    					w0=a[i].w;
    					a[i].t=true;
    					sign++;
    				}
    		}
    		printf("%d
    ",s);
    		for(i=0;i<n;i++)
    			a[i].t=false;
    	}
    	
    	fclose(stdin);
    	return 0;
    }
    

      

  • 相关阅读:
    本周学习进度条2
    web—图表表示数据库中的数据
    Intern Day36
    计算机网络
    面试
    C++
    计算机网络
    腾讯PC客户端开发暑期实习一面
    TCP和UDP
    Intern Day34
  • 原文地址:https://www.cnblogs.com/phaLQ/p/9353753.html
Copyright © 2011-2022 走看看