Simulate landlords-HDU 4930

Source: Internet
Author: User

Corresponding HDU question: Click to open the link

 

Fighting the landlords

Time Limit: 2000/1000 MS (Java/others) memory limit: 262144/262144 K (Java/Others)
Total submission (s): 986 accepted submission (s): 360


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 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.
 


 

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 handle t 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
433A233A2233225559T9993
 


 

Sample output
YesNoYesYes

 

 

Question: A is a hand card. Ask a if a can finish playing the card once or B won't be able to answer the card after a's play. It's hard to start thinking that a wants to finish playing the whole hand card (⊙ _ ⊙ )...

Group card: single, pair, three, 3, 1, 3, 2 (To clip a pair ...), 4 (bombs), 4 clips, 2 (cards can be different), XY (Wang fried)

 

Train of Thought: first judge whether a has a king blow. If yes, yes. If a does not finish it once and B has a king blow, no, then judge if a has a bomb and is bigger than B, yes; otherwise, if B has a bomb, no; then judge other (in order )...

 

 

 

 

# Include <cstdio> # include <cstdlib> # include <cmath> # include <map> # include <queue> # include <stack> # include <vector> # include <algorithm> # include <cstring> # include <string> # include <iostream> const int maxn = 1000 + 10; using namespace STD; struct card // saves the maximum value of each group card (such as 3 clips, 2, and 2) in the two hands {card () {one = 0; two = 0; three = 0; three_1 = 0; three_2 = 0; four = 0; four_2 = 0; xy = 0; Len = 0;} int one, two, three, three_1, three_2, four, four_2, XY, Len;}; void CAL (Char * s, int * num) // calculates the number of cards. For example, num [14] indicates that a has num [14] sheets {for (INT I = 0; I <strlen (s); I ++) {If (s [I] = 'T') num [10] ++; if (s [I] = 'J') num [11] ++; If (s [I] = 'q') num [12] ++; if (s [I] = 'k') num [13] ++; If (s [I] = 'A') num [14] ++; if (s [I] = '2') num [15] ++; // pay attention to this... Do not put it in num [2]. If (s [I] = 'X') num [16] ++; If (s [I] = 'y ') num [17] ++; If ('3' <= s [I] & S [I] <= '9 ') num [s [I]-'0'] ++;} void attack (Card & C, int * num) // calculate the maximum value of each group of cards in c {If (Num [16] & num [17]) C. XY = 1; for (INT I = 3; I <= 17; I ++) {If (Num [I]) C. one = I; If (Num [I]> = 2) C. two = I; If (Num [I]> = 3) C. three = I; If (Num [I]> = 4) C. four = I; If (Num [I]> = 4 & C. len> = 6) C. four_2 = I; If (Num [I]> = 3 & C. len> = 5) {for (Int J = 1; j <= 15; J ++) if (I! = J & num [J]> = 2) {C. three_2 = I; break;} If (Num [I]> = 3 & C. len> = 4) C. three_1 = I ;}} bool first (char * s, card c) // you can determine whether the result can be completed at a time. {int Len = strlen (s); If (C. XY & 2 = Len) return 1; if (C. four & 4 = Len) return 1; if (C. four_2 & 6 = Len) return 1; if (C. three_2 & 5 = Len) return 1; if (C. three_1 & 4 = Len) return 1; if (C. three & 3 = Len) return 1; if (C. two & 2 = Len) return 1; if (C. one & 1 = Len) return 1; return 0;} Int main () {// freopen ("in.txt", "r", stdin); char S1 [20], S2 [20]; int T; scanf ("% d", & T); While (t --) {scanf ("% S % s", S1, S2); card C1, C2; c1.len = strlen (S1); c2.len = strlen (S2); int num1 [20] = {0}, num2 [20] = {0}; CAL (S1, num1 ); cal (S2, num2); attack (C1, num1); attack (C2, num2); If (first (S1, C1) {printf ("Yes \ n "); continue;} // If (c1.xy) {printf ("Yes \ n"); continue;} // If (c2.xy) {printf ("NO \ n"); continue;} // peer If (c1.four & c1.four> = c2.four) {printf ("Yes \ n"); Continue ;}// the attacker has a bomb and else {If (c2.four) {printf ("NO \ n"); Continue ;}// the error code is returned many times... If (c1.three _ 2 & c1.three _ 2> = c2.three _ 2) {printf ("Yes \ n"); continue ;} // There are 3 clips and 2 larger comparison parties if (c1.one> = c2.one) {printf ("Yes \ n"); continue ;} // compare large if (c1.two & c1.two> = c2.two) {printf ("Yes \ n"); continue ;} // If (c1.three & c1.three> = c2.three) {printf ("Yes \ n"); continue ;} // There are 3 large if (c1.three _ 1 & c1.three _ 1> = c2.three _ 1) {printf ("Yes \ n"); continue ;} // There are 3 clips and 1 larger comparison party printf ("NO \ n");} return 0 ;}


 

 

 

 

 

 

Simulate landlords-HDU 4930

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.