ZCC loves straight flush
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1038 Accepted Submission(s): 429
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.
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.
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
Source
Recommend
思路:
一开始没注意到suit 只能是啊a,b,c,d, 也以为卡片的顺序不能变,,又把问题想复杂了。
其实,只要 哈希花色和数字,然后暴力枚举
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 #include <stack> 6 #include <cctype> 7 #include <vector> 8 #include <cmath> 9 #include <map> 10 #include <queue> 11 12 #define ll long long 13 14 using namespace std; 15 16 int T; 17 int mi; 18 char s[10]; 19 int t[5][20]; 20 21 void solve() 22 { 23 int i,j,k; 24 int p; 25 for(i = 0;i < 4;i++){ 26 for(j = 1;j <= 10;j++ ){ 27 p = 0; 28 for(k = 0;k <=4 ;k++){ 29 if(t[i][ (j+k-1)%13+1 ]){ 30 p++; 31 } 32 } 33 mi = min(mi,5 - p); 34 } 35 } 36 } 37 38 int main() 39 { 40 //freopen("in.txt","r",stdin); 41 scanf("%d",&T); 42 for(int ccnt=1;ccnt<=T;ccnt++){ 43 //while(scanf("%d%s%s",&n,a,b)!=EOF){ 44 mi = 4; 45 int i; 46 int v; 47 memset(t,0,sizeof(t)); 48 for(i = 1;i <= 5;i++){ 49 scanf("%s",s); 50 v = s[1] - '0'; 51 if(strlen(s) == 3){ 52 v*=10; 53 v+=s[2] - '0'; 54 } 55 t[ s[0] - 'A' ][ v ] = 1; 56 } 57 solve(); 58 printf("%d ",mi); 59 } 60 return 0; 61 }