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\n",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;
}

  

 
时间: 2024-12-29 04:02:01

BestCoder Round #41 1001——ZCC loves straight flush的相关文章

暴力 BestCoder Round #41 1001 ZCC loves straight flush

题目传送门 1 /* 2 m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 3 ╰· 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 using namespace std; 11 12 const int MAXN = 1

HDU 5228 ZCC loves straight flush( BestCoder Round #41)

题目链接:pid=5228">ZCC loves straight flush pid=5228">题面: pid=5228"> ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 827    Accepted Submission(s): 340

字符串处理 BestCoder Round #43 1001 pog loves szh I

题目传送门 1 /* 2 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 using namespace std; 9 10 typedef long long ll; 11 const int MAXN = 1

[Water]Hdu 5228 ZCC loves straight flush

枚举法: #include <iostream> #include <cstring> #include <string> #include <cstdio> #include <queue> #include <set> typedef long long ll; using namespace std; const int MAXN=100005; bool has[52]; int f(int start){ if(start

hdu 5228 ZCC loves straight flush

#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <string> #include <ma

BestCoder Round #41 -- (A,B)

题目传送:BestCoder Round #41 A.ZCC loves straight flush 思路:简单题,不过刚开始没看清题,wa了好几次,然后才发现输入不连续也可以,就是说每个同一花色的牌都可以放在一块,不用在意输入顺序,感觉这里题目应该说清楚点好些 AC代码(略挫,比赛时写的都比较乱): #include <cstdio> #include <cstring> #include <iostream> #include <algorithm>

暴力 BestCoder Round #46 1001 YJC tricks time

题目传送门 1 /* 2 暴力:模拟枚举每一个时间的度数 3 详细解释:http://blog.csdn.net/enjoying_science/article/details/46759085 4 期末考结束第一题,看看题解找找感觉:) 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #include <vector> 10 #include <iostr

贪心 BestCoder Round #39 1001 Delete

题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思路一样 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 #include <algorithm> 11 using

BestCoder Round #1 1001 &amp;&amp; 1002 hdu 4857 4858

hdu 4857 逃生 第一题是拓扑排序,不是按照字典序最小输出,而是要使较小的数排在最前面..赛后弄了好久,才比较明白,我一直以为 反向建图,i从1到n,开始深搜dfs( i ),对i点的边,由小到大继续搜一下,同时标记搜过的数,搜过之后就不再搜,搜到底之后ans[cnt++] = u;这样顺序输出就是答案,后来经过超哥指点,才明白深搜贪心是错的.只有 反向建图,用优先队列把较大的数尽量排在前面,然后反序输出才是正解.. 1 #include<iostream> 2 #include<