|
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 175 Accepted Submission(s): 61 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. 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. 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
Source
Recommend
hujie
|
题意:斗地主。给你两个人手上的牌,现在轮到自己出,若自己能一次出完或者自己出的这一发对方没法接,则输出Yes,否则输出No。除了王每种牌还有4张,大王小王各一张。出牌方式有单牌、对子、3个、3带1、3带2、4带2、王炸、炸弹。
题解:模拟。
这个模拟比较复杂,我们可以通过充分利用函数来降低编程难度、增加程序可读性。
先把自己手牌读进字符串s1里,长度len1=strlen(s1),
调用函数void attack(const char s[20],const int &len,int h[20],int hh[6]),得到h1和hh1,h1[i]表示数值为i的牌有多少张(T为10,J为11,……,小王X为16,大王Y为17,这里可以有很多方法把字母和数字对应上),hh1[j]表示数值为j的h1[i]有多少个,即统计炸弹数量hh1[4]、三个数量hh1[3]、对子数量hh1[2]、单牌数量hh1[1]。
通过h1和hh1,我们可以很容易地判断能不能一下出完牌,像这样:
1 ///全出完 2 //cout<<hh1[1]<<','<<hh1[2]<<','<<hh1[3]<<','<<hh1[4]<<endl; 3 if(h1[17]==1 && h1[16]==1 && len1==2)return 1;///王炸 4 if(hh1[4]==1 && len1==6)return 1;///4带2 5 if(hh1[4]==1 && len1==4)return 1;///炸弹 6 else if(hh1[4]==0 && hh1[3]==1 && ( (len1==3) || (len1==4 && hh1[1]==1) || (len1==5 && hh1[2]==1) ))return 1;///3个、3带1、3带2 7 else if(hh1[4]==0 && hh1[3]==0 && hh1[2]==1 && hh1[1]==0 && len1==2)return 1;///一对 8 else if(len1==1)return 1;///一张