Hdu4930 fighting the landlords (simulate multi-school 6)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4930

Fighting the landlordstime limit: 2000/1000 MS (Java/others) memory limit: 262144/262144 K (Java/Others) Total submission (s): 546 accepted submission (s): 188

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


Question meaning:
Two people are set as a and B, and A and B are fighting for the landlord. The above line is the card in the hand of a, and the following line is the card in the hand of B, if a fails to play B for the first time or a finishes playing the card for the first time, yes is output. Otherwise, if a fails to play and B is pressed, no is output.


The Code is as follows:

# Include <cstdio> # include <iostream> # include <algorithm> # include <cstring> using namespace STD; # define M 26 char S1 [m], S2 [m]; int c1 [m], C2 [m]; int A1 [m], A2 [m]; int B1 [m], B2 [m]; int len1, len2; int max (int A, int B) {return A> B? A: B;} void Init () {memset (A1, 0, sizeof (A1); memset (B1, 0, sizeof (B1); memset (A2, 0, sizeof (A1); memset (B2, 0, sizeof (B2); memset (C1, 0, sizeof (C1); memset (C2, 0, sizeof (C2);} int F (char c) {If (C> = '3' & C <= '9') return C-'2 '; if (C = 'T') return 8; If (C = 'J') return 9; If (C = 'q') return 10; if (C = 'k') return 11; If (C = 'A') return 12; If (C = '2') Return 13; if (C = 'X') return 14; If (C = 'y') Return 15;} void find (int * C, int flag) {int I; int A [6], B [6]; memset (A, 0, sizeof (a); memset (B, 0, sizeof (B); for (I = 1; I <= 13; I ++) {If (C [I]) {B [1] = max (B [1], I); If (C [I] = 1) // single {A [1] ++;} else if (C [I] = 2) // pair {A [2] ++; B [2] = max (B [2], I);} else if (C [I] = 3) // three {A [3] ++; B [3] = max (B [3], I);} else if (C [I] = 4) // bomb {A [4] ++; B [4] = max (B [4], I) ;}} if (C [14] & C [15]) // double king {B [1] = 15; A [5] ++;} else if (C [15]) // {B [1] = 15;} else if (C [14]) // John {B [1] = 14 ;}for (I = 1; I <= 5; I ++) {If (flag = 1) {A1 [I] = A [I]; B1 [I] = B [I];} else if (flag = 2) {A2 [I] = A [I]; B2 [I] = B [I] ;}} void solve () {int I, j; int flag1, flag2; int n1 = strlen (S1); int n2 = strlen (S2); If (n1 = 1) | (n1 = 2 & A1 [2]) | (n1 = 3 & A1 [3]) | (n1 = 4 & (A1 [4] | A1 [3]) | (n1 = 5 & A1 [2] & A1 [3]) | (n1 = 6 & A1 [2] & A1 [4]) {Printf ("Yes \ n"); // once Output} else if (A1 [5]) {printf ("Yes \ n "); // A has a king in his hand} else if (A2 [5]) {printf ("NO \ n "); // B has a king blow} else if (b1 [4]> B2 [4]) {printf ("Yes \ n "); // A has more bombs than B.} else if (b1 [4] <B2 [4]) // reverse {printf ("NO \ n ");} else if (b1 [1]> B2 [1]) // the Outgoing order, which is larger than that of B {printf ("Yes \ n ");} else if (b1 [2]> B2 [2]) // compare to B's large {printf ("Yes \ n ");} else if (b1 [3] & (b1 [3]> B2 [3] | (b1 [1] &! B2 [1]) | (b1 [2] &! B2 [2]) {// when three images are generated, either one or two images can be taken or not. In turn, printf ("Yes \ n") is determined ");} else {printf ("NO \ n") ;}} int main () {int t; int I, j; scanf ("% d", & T ); while (t --) {Init (); scanf ("% s", S1); scanf ("% s", S2); len1 = strlen (S1 ); len2 = strlen (S2); for (I = 0; I <len1; I ++) {c1 [F (S1 [I])] ++ ;} for (I = 0; I <len2; I ++) {c2 [F (s2 [I])] ++;} Find (C1, 1); find (C2, 2); solve ();} return 0 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.