- 问题描述
-
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; }
NOJ [1135] Hexadecimal RGB Color
最新推荐文章于 2024-03-26 09:07:37 发布