HDU 5228

 1 #include<stdio.h>
 2 #include<string.h>
 3 int hash[4*13];
 4 int main(){
 5     int t;
 6     scanf("%d",&t);
 7     while(t--){
 8         char ch;
 9         int num;
10         memset(hash,0,sizeof(hash));
11         for(int i = 0;i<5;i++){
12             scanf(" %c",&ch);
13             scanf("%d",&num);
14             num--;//下标要从0开始 
15             hash[4*num+ch-'A']++;//hash,0-->1A,1-->1B,2-->1C......
16         }
17         int ans = 5;
18         for(int i = 0;i<10;i++){//下标到9就好了,因为k会枚举后面4个的 
19             for(int j = 0;j<4;j++){
20                 int temp = 5;
21                 for(int k = 0;k<5;k++){
22                     int index = (i+k)*4+j;
23                     if(hash[index%(13*4)])//这里取余是当枚举到13A、13B的时候,取余回到1A、1B... 
24                         temp--;
25                 }
26                 ans = ans<temp?ans:temp;
27             }
28         }
29         printf("%d\n",ans);
30     }
31     return 0;
32 } 

 

posted @ 2015-11-08 16:44  张秦遥  阅读(184)  评论(0编辑  收藏  举报