Fighting the landlords
Time Limit: 2000/1000 MS (Java/others) memory limit: 262144/262144 K (Java/Others)
Total submission (s): 480 accepted submission (s): 163
Problem descriptionfighting 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 shocould be different rank of cards (e.g. 3-3-3-a, 4-4-4-x etc .). here,
Kicker's rank is irrelevantTo 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-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 should t nuke or another bomb with a higher rank. the rank of bombs follows the rank of Individual cards: 2-2-2 is the highest and 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.
Inputthe 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 handle t that the two jokers each occurs only once.
Outputfor each test case, output yes if you can reach your goal, otherwise output No.
Sample Input
433A233A2233225559T9993
Sample output
YesNoYesYes
Authorbupt
Source2014 multi-university training contest 6
Code:
# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> using namespace STD; struct node {int solo [20], num_solo; int pair [20], num_pair; int trio [20], num_trio; int four [20], num_four; int nuke;} n [2]; void work (char s [], int d) {int Len = strlen (s); memset (& N [d], 0, sizeof (N [0]); N [D]. num_solo = Len; For (INT I = 0; I <Len; I ++) {If (s [I]> = '3' & S [I] <= '9') N [D]. solo [s [I]-'2'] ++; els E if (s [I] = 'T') N [D]. solo [8] ++; else if (s [I] = 'J') N [D]. solo [9] ++; else if (s [I] = 'q') N [D]. solo [10] ++; else if (s [I] = 'k') N [D]. solo [11] ++; else if (s [I] = 'A') N [D]. solo [12] ++; else if (s [I] = '2') N [D]. solo [13] ++; else if (s [I] = 'X') N [D]. solo [14] ++; else if (s [I] = 'y') N [D]. solo [15] ++;} For (INT I = 1; I <= 13; I ++) {If (N [D]. solo [I]> = 2) N [D]. pair [I] ++, N [D]. num_pair ++; If (N [D]. solo [I]> = 3) N [D]. trio [I] ++, N [d ]. Num_trio ++; If (N [D]. solo [I]> = 4) N [D]. four [I] ++, N [D]. num_four ++;} If (N [D]. solo [14] & N [D]. solo [15]) N [D]. nuke = 1; return;} bool solve () {// consider the case of dual kings if (N [0]. nuke) return true; // If (N [0]. num_solo = 1) return true; If (N [0]. num_pair & N [0]. num_solo = 2) return true; If (N [0]. num_trio & N [0]. num_solo = 3) return true; If (N [0]. num_four & N [0]. num_solo = 4) return true; If (N [0]. num_trio & N [0]. num_solo = 4) Re Turn true; If (N [0]. num_trio & N [0]. num_pair> = 2 & N [0]. num_solo = 5) return true; If (N [0]. num_four & N [0]. num_solo = 6) return true; // if I cannot go out at a time, the other party has the biggest card. No matter what I do, it will not work if (N [1]. nuke) return false; // consider the type of the card that I have and the other party does not have. // consider the correct case if (N [0]. num_pair &&! N [1]. num_pair) return true; // consider three cases if (N [0]. num_trio &&! N [1]. num_trio) return true; // If (N [0]. num_four &&! N [1]. num_four) return true; // If (N [0] for the case of three-band-one. num_trio & N [0]. num_solo> = 4 & N [1]. num_solo <4 &&! N [1]. num_four) return true; // If (N [0] In case of Tri-Band 2. num_trio & N [0]. num_pair> = 2 & N [1]. num_solo <5 &&! N [1]. num_four) return true; // consider if (N [0] In case of four band 2. num_four & N [0]. num_solo> = 6 & N [1]. num_solo <6 &&! N [1]. num_four) return true; // consider the type of the cards I have. In other cases, int L = 0, r = 0; // consider a card situation for (INT I = 1; I <= 15; I ++) {If (N [0]. solo [I]) L = I; If (N [1]. solo [I]) r = I;} If (L> = R &&! N [1]. num_four) return true; // consider the case of two cards if (N [0]. num_pair) {L = 0; r = 0; For (INT I = 1; I <= 13; I ++) {If (N [0]. pair [I]) L = I; If (N [1]. pair [I]) r = I;} If (L> = R &&! N [1]. num_four) return true;} // consider the case of three cards if (N [0]. num_trio) {L = 0; r = 0; For (INT I = 1; I <= 13; I ++) {If (N [0]. trio [I]) L = I; If (N [1]. trio [I]) r = I;} If (L> = R &&! N [1]. num_four) return true;} // consider the four cards if (N [0]. num_four) {L = 0; r = 0; For (INT I = 1; I <= 13; I ++) {If (N [0]. four [I]) L = I; If (N [1]. four [I]) r = I;} If (L> = r) return true;} return false;} int main () {char S1 [25], s2 [25]; int t; scanf ("% d", & T); While (t --) {scanf ("% S % s", S1, S2 ); work (S1, 0); Work (S2, 1); If (solve () printf ("Yes \ n"); else printf ("NO \ n ");} return 0 ;}