首页 > 代码库 > HDU4930:Fighting the Landlords(模拟)
HDU4930:Fighting the Landlords(模拟)
Problem Description
Fighting the Landlords is a card game which has been a heat for years in China. The game goes with the 54 poker cards for 3 players, where the “Landlord” has 20 cards and the other two (the “Farmers”) have 17. The Landlord wins if he/she has no cards left, and the farmer team wins if either of the Farmer have no cards left. The game uses the concept of hands, and some fundamental rules are used to compare the cards. For convenience, here we only consider the following categories of cards:
1.Solo: a single card. The priority is: Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3. It’s the basic rank of cards.
2.Pair : two matching cards of equal rank (e.g. 3-3, 4-4, 2-2 etc.). Note that the two Jokers cannot form a Pair (it’s another category of cards). The comparison is based on the rank of Solo, where 2-2 is the highest, A-A comes second, and 3-3 is the lowest.
3.Trio: three cards of the same rank (e.g. 3-3-3, J-J-J etc.). The priority is similar to the two categories above: 2-2-2 > A-A-A > K-K-K > . . . > 3-3-3.
4.Trio-Solo: three cards of the same rank with a Solo as the kicker. Note that the Solo and the Trio should be different rank of cards (e.g. 3-3-3-A, 4-4-4-X etc.). Here, the Kicker’s rank is irrelevant to the comparison, and the Trio’s rank determines the priority. For example, 4-4-4-3 > 3-3-3-2.
5.Trio-Pair : three cards of the same rank with a Pair as the kicker (e.g. 3-3- 3-2-2, J-J-J-Q-Q etc.). The comparison is as the same as Trio-Solo, where the Trio is the only factor to be considered. For example,4-4-4-5-5 > 3-3-3-2-2. Note again, that two jokers cannot form a Pair.
6.Four-Dual: four cards of the same rank with two cards as the kicker. Here, it’s allowed for the two kickers to share the same rank. The four same cards dominates the comparison: 5-5-5-5-3-4 > 4-4-4-4-2-2.
In the categories above, a player can only beat the prior hand using of the same category but not the others. For example, only a prior Solo can beat a Solo while a Pair cannot. But there’re exceptions:
7.Nuke: X-Y (JOKER-joker). It can beat everything in the game.
8.Bomb: 4 cards of the same rank. It can beat any other category except Nuke or another Bomb with a higher rank. The rank of Bombs follows the rank of individual cards: 2-2-2-2 is the highest and 3-3-3-3 is the lowest.
Given the cards of both yours and the next player’s, please judge whether you have a way to play a hand of cards that the next player cannot beat you in this round.If you no longer have cards after playing, we consider that he cannot beat you either. You may see the sample for more details.
1.Solo: a single card. The priority is: Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3. It’s the basic rank of cards.
2.Pair : two matching cards of equal rank (e.g. 3-3, 4-4, 2-2 etc.). Note that the two Jokers cannot form a Pair (it’s another category of cards). The comparison is based on the rank of Solo, where 2-2 is the highest, A-A comes second, and 3-3 is the lowest.
3.Trio: three cards of the same rank (e.g. 3-3-3, J-J-J etc.). The priority is similar to the two categories above: 2-2-2 > A-A-A > K-K-K > . . . > 3-3-3.
4.Trio-Solo: three cards of the same rank with a Solo as the kicker. Note that the Solo and the Trio should be different rank of cards (e.g. 3-3-3-A, 4-4-4-X etc.). Here, the Kicker’s rank is irrelevant to the comparison, and the Trio’s rank determines the priority. For example, 4-4-4-3 > 3-3-3-2.
5.Trio-Pair : three cards of the same rank with a Pair as the kicker (e.g. 3-3- 3-2-2, J-J-J-Q-Q etc.). The comparison is as the same as Trio-Solo, where the Trio is the only factor to be considered. For example,4-4-4-5-5 > 3-3-3-2-2. Note again, that two jokers cannot form a Pair.
6.Four-Dual: four cards of the same rank with two cards as the kicker. Here, it’s allowed for the two kickers to share the same rank. The four same cards dominates the comparison: 5-5-5-5-3-4 > 4-4-4-4-2-2.
In the categories above, a player can only beat the prior hand using of the same category but not the others. For example, only a prior Solo can beat a Solo while a Pair cannot. But there’re exceptions:
7.Nuke: X-Y (JOKER-joker). It can beat everything in the game.
8.Bomb: 4 cards of the same rank. It can beat any other category except Nuke or another Bomb with a higher rank. The rank of Bombs follows the rank of individual cards: 2-2-2-2 is the highest and 3-3-3-3 is the lowest.
Given the cards of both yours and the next player’s, please judge whether you have a way to play a hand of cards that the next player cannot beat you in this round.If you no longer have cards after playing, we consider that he cannot beat you either. You may see the sample for more details.
Input
The input contains several test cases. The number of test cases T (T<=20) occurs in the first line of input.
Each test case consists of two lines. Both of them contain a string indicating your cards and the next player’s, respectively. The length of each string doesn’t exceed 17, and each single card will occur at most 4 times totally on two players’ hands except that the two Jokers each occurs only once.
Each test case consists of two lines. Both of them contain a string indicating your cards and the next player’s, respectively. The length of each string doesn’t exceed 17, and each single card will occur at most 4 times totally on two players’ hands except that the two Jokers each occurs only once.
Output
For each test case, output Yes if you can reach your goal, otherwise output No.
Sample Input
4 33A 2 33A 22 33 22 5559T 9993
Sample Output
Yes No Yes Yes斗地主,只有最简单的规则一手定输赢#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define sss1 {ans(1);continue;} #define sss0 {ans(0);continue;} char s1[20],s2[20]; int p1[16],p2[16],len1,len2; int a[8],b[8],kk[10] = {0,0,0,14,13,12,11,10,9,8}; int check(char c) { if(c == 'Y') return 0; if(c == 'X') return 1; if(c == '2') return 2; if(c == 'A') return 3; if(c == 'K') return 4; if(c == 'Q') return 5; if(c == 'J') return 6; if(c == 'T') return 7; for(int i = '9';i>='3';i--) { if(c == i) return kk[i-'0']; } } void ans(int i) { if(i==1) printf("Yes\n"); else printf("No\n"); } int Solo() { int i; for(i = 0; i<15; i++) { if(p1[i]) return 1; if(p2[i]) return 0; } } int Pair() { int i; for(i = 2; i<15; i++) { if(p1[i]>=2) return 1; if(p2[i]>=2) return 0; } } int Trio() { int i; for(i = 2; i<15; i++) { if(p1[i]>=3) return 1; if(p2[i]>=3) return 0; } } int Bomb() { int i; for(i = 2; i<15; i++) { if(p1[i]>=4) return 1; if(p2[i]>=4) return 0; } } int main() { int t,i,j; scanf("%d",&t); while(t--) { scanf("%s%s",s1,s2); len1 = strlen(s1); len2 = strlen(s2); memset(p1,0,sizeof(p1)); memset(p2,0,sizeof(p2)); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(i = 0; i<len1; i++) p1[check(s1[i])]++; for(i = 0; i<len2; i++) p2[check(s2[i])]++; for(i = 0; i<15; i++) { a[p1[i]] = 1; b[p2[i]] = 1; } int flag = 0; if(p1[0]&&p1[1] || len1 == 1 || (a[2]&&len1==2) || (a[3]&&len1==3) || (a[4]&&len1==4) || (a[3]&&len1==4) || (a[3]&&a[2]&&len1==5) || (a[4]&&len1==6)) sss1; if(p2[0] && p2[1]) sss0; if(a[4] && !b[4]) sss1; if(b[4] && !a[4]) sss0; if(a[4] && b[4]) { if(Bomb()) sss1 else sss0 } if(a[3] && !b[3]) sss1; if(a[3] && b[3]) { if(Trio()) sss1 else { if(len1 >= 4 && len2<4) sss1 else if(a[2] && (!b[2]||len2<5)) sss1 } } if(a[2] && !b[2] && !b[3]) sss1 if(a[2] && (b[2]||b[3])) { if(Pair()) sss1 } if(Solo()) sss1 sss0 } return 0; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。