H - ZCC loves straight flush

来源:互联网 发布:仿ios日历 js插件 编辑:程序博客网 时间:2024/05/18 00:36

H - ZCC loves straight flush
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

After losing all his chips when playing Texas Hold'em with Fsygd on the way to ZJOI2015, ZCC has just learned a black technology. Now ZCC is able to change all cards as he wants during the game. ZCC wants to get a Straight Flush by changing as few cards as possible. 

We call a five-card hand a Straight Flush when all five cards are consecutive and of the same suit. You are given a five-card hand. Please tell ZCC how many cards must be changed so as to get a Straight Flush. 
   
Cards are represented by a letter('A', 'B', 'C', 'D') which denotes the suit and a number('1', '2', $\cdots$, '13') which denotes the rank. 
   
Note that number '1' represents ace which is the largest actually. "1 2 3 4 5" and "10 11 12 13 1" are both considered to be consecutive while "11 12 13 1 2" is not. 

Input

First line contains a single integer $T(T=1000)$ which denotes the number of test cases. 
For each test case, there are five short strings which denote the cards in a single line. It's guaranteed that all five cards are different.

Output

For each test case, output a single line which is the answer.

Sample Input

3A1 A2 A3 A4 A5A1 A2 A3 A4 C5A9 A10 C11 C12 C13

Sample Output

012
一开始这个题感觉很复杂,要考虑的情况太多,后来发现其实只要枚举就行,一开始考虑的程序只是考虑了数字连续的情况,认为A1 A5 C1 C10 D8这种情况下没有连续的数字,应当改变的牌的个数是4,后来发现其实是改变三张,加上A2 A3 A4就可以了,因为没考虑到这种情况,所以一直A不过,==...,最后发现真的是服自己了,菜死了,做题考虑情况太不全面
AC代码:
  

#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cstring>


using namespacestd;

int t[15][5];

int main()

{

    int n,num,max,cnt;

    char suit;

    string  s;

    cin>>n;

    while(n--)

    {

        max=1,cnt=0,num=0;

        memset(t,0,sizeof(t));

        for(int  i=0;i<5;i++)

        {

            cin>>s;

            for(int j=1;s[j]!='\0';j++)

            {

                num=num*10+s[j]-'0';

            }

            suit=s[0];

            t[num][suit-'A'+1]=1;

            if(num==1)

                t[14][suit-'A'+1]=1;

            num=0;

        }

    

        for(int i=1;i<=4;i++)//关键代码部分

        {

            

            for(int j=1;j<=10;j++)

            {

                cnt=0;

                for(int k=0;k<5;k++)

                {

                    if(t[j+k][i]==1)

                        cnt++;

                }

                 if(max<cnt)

                     max=cnt;

            }

            

        }

        cout<<5-max<<endl;

    }

    return0;

}


0 0
原创粉丝点击