• BestCoder Round #41 1001——ZCC loves straight flush


    Problem 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', , '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
    3
    A1 A2 A3 A4 A5
    A1 A2 A3 A4 C5
    A9 A10 C11 C12 C13
    Sample Output
    0
    1
    2
    大意:要形成同花顺,问换掉的最少的牌的数目,,自己代码能力还是ruoruoruo,枚举每一种情况,再找在这种情况里面相同的牌的个数,res--,遍历所有情况的最少值就是答案
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int a[20],b[20],sa[20],sb[20];
    void work()
    {
        int ans = 5;
        for(int i = 'A'; i <= 'D'; i++){
            for(int j = 1; j <= 10; j++){
                for(int k = 1; k <= 5; k++){
                    sa[k] = i;
                    sb[k] = j + k - 1;
                    if(sb[k] == 14) sb[k] = 1;
                }
                int res = 5;
                for(int k = 1; k <= 5; k++){
                    for(int l = 1; l <= 5; l++){
                        if(a[k] == sa[l] && b[k] == sb[l])
                            res--;
                    }
                }
                if(res < ans) ans = res;
            }
        }
        printf("%d
    ",ans);
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--){
            for(int i = 1; i <= 5; i++){
                scanf(" %c%d",&a[i],&b[i]);
            }
            work();
        }
        return 0;
    }
    

      

     
  • 相关阅读:
    .net开发环境的选择
    html头部的一些信息
    SQLHelper类
    C#实现文件下载
    js类
    Winform小知识点
    emacs 代码缩进
    自己喜欢的shell终端配置
    time_wait过多的优化
    Emacs 电子邮件组件RMAIL
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4510360.html
Copyright © 2020-2023  润新知