NOJ [1135] Hexadecimal RGB Color

  • 问题描述
  • In programming, Photoshop and some other areas, the color always displayed in hexadecimal. The format is #RRGGBB. For example, red is #FF0000.

    Now we define that a color RRGGBB is rigorously deeper than R'R'G'G'B'B' only when RR is less than R'R', GG is less than G'G' and BB is less than B'B'.

    We give you several colors in hexadecimal, you have to pick up some colors and make them from deep to shallow. And you must pick as more as you can.

  • 输入
  • This problem has several cases, input until EOF.
    The first line of each case is an integer N (0 < N <= 2000).
    Then follow N lines, each line is a color formatted as #RRGGBB.
  • 输出
  • For each case, you should output that the maximum number of colors you can pick up.



    和上一篇文章的那题一样,就是最长上升序列
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    
    using namespace std;
    
    struct color
    {
    	int c1,c2,c3;
    }colors[2003];
    int zhuanhuan[130];
    int dp[2003];
    int cmp(color a,color b )
    {
    	if(a.c1<b.c1)
    		return true;
    	else if(a.c1>b.c1)
    		return false;
    	else
    	{
    		if(a.c2<b.c2)
    		  return true;
    	    else if(a.c2>b.c2)
    		  return false;
    		else
    		{
    			if(a.c3<b.c3)
    		      return true;
    	        else
    		      return false;
    		}
    	}
    }
    
    int main()
    {
    	int n;
    	zhuanhuan['0']=0;
        zhuanhuan['1']=1;
    	zhuanhuan['2']=2;
    	zhuanhuan['3']=3;
    	zhuanhuan['4']=4;
    	zhuanhuan['5']=5;
    	zhuanhuan['6']=6;
    	zhuanhuan['7']=7;
    	zhuanhuan['8']=8;
    	zhuanhuan['9']=9;
    	zhuanhuan['A']=10;
    	zhuanhuan['B']=11;
    	zhuanhuan['C']=12;
    	zhuanhuan['D']=13;
    	zhuanhuan['E']=14;
    	zhuanhuan['F']=15;
    	zhuanhuan['a']=10;
    	zhuanhuan['b']=11;
    	zhuanhuan['c']=12;
    	zhuanhuan['d']=13;
    	zhuanhuan['e']=14;
    	zhuanhuan['f']=15;
    	while(~scanf("%d",&n))
    	{
    		int i,j;
    		char temp[10];
    		for(i=0;i<n;i++)
    		{
    			scanf("%s",temp);
    			colors[i].c1=zhuanhuan[temp[1]]*16+zhuanhuan[temp[2]];
    			colors[i].c2=zhuanhuan[temp[3]]*16+zhuanhuan[temp[4]];
    			colors[i].c3=zhuanhuan[temp[5]]*16+zhuanhuan[temp[6]];
    		}
    		sort(colors,colors+n,cmp);
    		memset(dp,0,sizeof(dp));
    		dp[0]=1;
    		int max=-1;
    		for(i=1;i<n;i++)
    		{
    			int ans=0;
    			for(j=0;j<i;j++)
    			{
    				if(colors[j].c1<colors[i].c1  && colors[j].c2<colors[i].c2 && colors[j].c3<colors[i].c3 && dp[j]>ans)
    					ans=dp[j];
    			}
    			dp[i]=ans+1;
    			if(max<dp[i])
    				max=dp[i];
    		}
    		printf("%d\n",max);
    	}
    	return 0;
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值