ZCC loves straight flush HDU - 5228(暴力)
2017-01-24 02:02
441 查看
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.
InputFirst line contains a single integer T(T=1000)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.OutputFor each test case, output a single line which is the answer.Sample Input
Sample Output
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.
InputFirst line contains a single integer T(T=1000)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.OutputFor 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
题意:枚举各种类型的同花顺,遍历看有几个存在的不存在的就是需要修改的
题目大意:ZCC想要通过更换尽量少的牌得到同花顺。 称五张牌构成了同花顺,当且仅当它们的数值连续,花色一致。请告诉ZCC他至少需要更换多少张牌。 在题目中,牌的花色用一个大写字母('A', 'B', 'C', 'D')来表示,而数值用数字('1', '2', ⋯, '13')来表示。 注意数字1代表ace,在德州扑克中是最大的牌。"1 2 3 4 5" 和 "10 11 12 13 1" 都被认为是连续的。而"11 12 13 1 2"并不是。
并不是很难的一个暴力解法,但是却不好想。
主要就是遍历测试有多少个符合正序,取符合的最大值
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; int main() { int n,t[4][15],ans,q; char p; scanf("%d",&n); getchar(); while(n--) { memset(t,0,sizeof(t)); for(int i=1;i<=5;i++) { scanf("%c%d",&p,&q); t[p-'A'][q]=1;//此处对于字符和数字,将字符转化为数字int更为巧妙 getchar(); } ans=4; for(int i=0;i<4;i++) { for(int j=1;j<=10;j++) { q=0; for(int k=0;k<5;k++) { if(t[i][(j+k-1)%13+1])//对于13来说13%13==0所以需要先减一后加一 { q++; } } ans=min(5-q,ans); } } printf("%d\n",ans); } return 0; }
相关文章推荐
- 1.一些 贪心算法 的简单思维题:
- 贪心算法——字典序最小问题
- 贪心算法——区间调度问题
- 贪心----书架
- Jump Game I,II 贪心
- Wildcard Matching
- 贪心法实现无向图的划分 代码
- 贪心题目循环和控制台折行
- HDOJ 1009
- super oj p528
- 【解题报告】【USACO】酸奶工厂
- 【解题报告】【】交谊舞
- POJ 1328
- Best Cow Line
- HDU 1009 Fatmouse's Trade
- POJ2377 Bad Cowtractors
- 贪心 hdu 1003
- 最大容器
- 满足和为定值的两个数或多个数
- 【BZOJ】3016: [Usaco2012 Nov]Clumsy Cows