Fighting the landlords
Time Limit: 2000/1000 MS (Java/others) memory limit: 262144/262144 K (Java/Others)
Total submission (s): 160 accepted submission (s): 52
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
Question: two people play poker. The Rules refer to landlords. Ask if the first hand can finish or give the first hand card at a time so that the other party has no card !!
The simulation is as follows:
# Include "stdio. H "# include" string. H "# define N 20 # define M 100int A [n], B [N], n, m; char s [N]; int max (int A, int B) {return A> B? A: B;} void Inti (char * s, int f) {int I, T; for (I = 0; s [I]! = '\ 0'; I ++) {If (s [I]> = '3' & S [I] <= '9 ') {T = s [I]-'0'-2;} else if (s [I] = 'T') t = 8; else if (s [I] = 'J') t = 9; else if (s [I] = 'q') t = 10; else if (s [I] = 'k') t = 11; else if (s [I] = 'A') t = 12; else if (s [I] = '2') t = 13; else if (s [I] = 'X') t = 14; else if (s [I] = 'y') t = 15; If (F = 1) A [T] ++; else B [T] ++ ;}} int escape () {int I; If (n = 1) // enumerate the number of cards we have. Can I return 1 at a time; if (n = 2) {int n2 = 0; for (I = 1; I <14; I ++) if (a [I] = 2) n2 ++; If (n2 = 1) return 1 ;}if (n = 3) {int N3 = 0; for (I = 1; I <14; I ++) if (A [I] = 3) N3 ++; If (N3 = 1) return 1;} If (n = 4) {int N3 = 0; for (I = 1; I <14; I ++) {if (a [I]> = 3) N3 ++;} If (N3 = 1) return 1 ;}if (n = 5) {int n2 = 0, N3 = 0; for (I = 1; I <14; I ++) {if (a [I] = 3) N3 ++; if (a [I] = 2) N2 ++ ;} if (n2 = 1 & N3 = 1) return 1 ;}if (n = 6) {int N4 = 0; for (I = 1; I <14; I ++) {if (a [I] = 4) N4 ++;} If (n4 = 1) return 1;} return 0;} int beat () {Int I, j; if (a [14] = 1 & A [15] = 1) return 1; if (B [14] = 1 & B [15] = 1) return 0; // the other party has a king blow for (I = 13; I> 0; I --) if (a [I] = 4) break; For (j = 13; j> 0; j --) if (B [J] = 4) break; if (j> 0) // the other party has a bomb, {if (I> = J) return 1; else return 0;} If (n> = 5) // The following figure shows that the other party does not have a bomb. {// It outputs 3 with 2. The following 3 with 1 does not need to enumerate int A3, A2, B3, B2; a3 = a2 = B3 = b2 = 0; for (I = 13; I> 0; I --) {if (a [I] = 3) A3 = max (A3, i); if (a [I] = 2) a2 = max (A2, I) ;}for (j = 13; j> 0; j --) {If (B [J] = 3) B3 = m Ax (B3, J); If (B [J] = 2) b2 = max (B2, J);} If (A3! = 0 & A2! = 0) {If (A3 >= B3 | b2 = 0) return 1 ;}// four cards can only be a bomb or 3 band 1, if (n> = 3) {for (I = 13; I> 0; I --) if (a [I]> = 3) break; For (j = 13; j> 0; j --) if (B [J]> = 3) break; if (I! = 0) {if (I >= J) return 1 ;}} if (N >=2) {for (I = 13; I> 0; I --) if (A [I]> = 2) break; For (j = 13; j> 0; j --) if (B [J]> = 2) break; if (I! = 0) {if (I >= J) return 1 ;}} if (N >= 1) // a card is displayed without a bomb {for (I = 15; i> 0; I --) if (a [I]) break; For (j = 15; j> 0; j --) if (B [J]) break; if (I> = J) return 1;} return 0;} int main () {int t; scanf ("% d", & T); While (t --) {memset (A, 0, sizeof (a); memset (B, 0, sizeof (B); scanf ("% s", S ); N = strlen (s); Inti (s, 1); scanf ("% s", S); M = strlen (s); Inti (S, 2 ); if (escape () // can the card be played once {printf ("Yes \ n"); continue;} If (beat ()) // printf ("Yes \ n"); else printf ("NO \ n");} return 0 ;}