F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Fight the Landlord

Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 253    Accepted Submission(s): 44


Problem Description
Fight the Landlord (¶·µØÖ÷) is a card game for three players. In each hand one player, the "landlord", plays alone and the others form a team(may called two peasants). The landlord's aim is to be the first to play out all his cards in valid combinations, and the team wins if any one of them manages to play all their cards before the landlord.

A complete deck consists of 52 standard cards plus 2 jokers, red and black. The cards rank from high to low: R(Red Joker), B(Black joker), 2, A, K, Q, J, T(10), 9, 8, 7, 6, 5, 4, 3. Each rank of standard card has 4 cards.

The landlord plays first, and may play a single card or any legal combination. Each subsequent player in anticlockwise order must either pass (play no card) or beat the previous play by playing a higher combination of the same number of cards and same type. There are just two exceptions to this: a rocket can beat any combination, and a bomb can beat any combination except a higher bomb or rocket - see definitions below.

In this game, there are thirteen types of combination that can be played:

1.  Single card - ranking from 3 (low) up to red joker (high) as explained above.
2.  Pair - two cards of the same rank, from 3 (low) up to 2 (high), for example 3-3, A-A.
3.  Triplet - three cards of the same rank, for example 9-9-9.
4.  Triplet with an attached card - a triplet with a single card added, the single card must be different from the triplet, for example 6-6-6-8. These rank according to the rank of the triplet - so for example 9-9-9-3 beats 8-8-8-A.
5.  Triplet with an attached pair - a triplet with a pair added, the ranking being determined by the rank of the triplet - for example Q-Q-Q-6-6 beats 10-10-10-K-K.
6.  Sequence - at least five cards of consecutive rank, from 3 up to ace - for example 8-9-10-J-Q. 2 and jokers cannot be used.
7.  Sequence of pairs - at least three pairs of consecutive ranks, from 3 up to A. 2 and jokers cannot be used. For example 10-10-J-J-Q-Q-K-K.
8.  Sequence of triplets - at least two triplets of consecutive ranks from 3 up to A. 2 cannot be used. For example 4-4-4-5-5-5.
9.  Sequence of triplets with attached cards - an extra card is added to each triplet. Only the triplets have to be in sequence, for example 7-7-7-8-8-8-3-6. The attached cards must be different from all the triplets and from each other. Although triplets of 2 cannot be included in the triplets sequence, a 2 or a joker or one of each can be attached, but not both jokers.
10.  Sequence of triplets with attached pairs - an extra pair is attached to each triplet. Only the triplets have to be in sequence - for example 8-8-8-9-9-9-4-4-J-J. The pairs must be different in rank from each other and from all the triplets. Although triplets of 2 cannot be included in the triplets sequence, a pair of 2 can be attached. Note that attached single cards and attached pairs cannot be mixed - for example 3-3-3-4-4-4-6-7-7 is not valid.
11.  Bomb - four cards of the same rank. A bomb can beat everything except a rocket or a bomb with higher rank.
12.  Rocket - a pair of jokers. It is the highest combination and beats anything else, including bombs.
13.  Quadplex set - there are two types: a quad (four cards of the same rank) with two single cards of different ranks attached, such as 6-6-6-6-8-9, or a quad with two pairs of different ranks attached, such as J-J-J-J-9-9-Q-Q. 2 and jokers can be attached, but you cannot use both jokers in one quadplex set. Quadplex sets are ranked according to the rank of the quad. Note that a quadplex set can only beat a lower quadplex set of the same type, and cannot beat any other type of combination. Also a quadplex set can be beaten by a bomb made of lower ranked cards.

At the beginning of each round, the landlord has 20 cards and the others each get 17 cards, can the landlord has a strategy to bring out his cards all the way alone until he wins the game and leave no chance for the others to play?
 

Input
The first line of the input is T, which stands for the number of test cases you need to solve.

For each case, three lines are given. The first line contains 20 characters describes 20 cards in landlord¡¯s hand. The following two lines each contains 17 characters describe the two peasants¡¯ cards. It is guaranteed that the given 54 cards make up a complete deck.

 

Output
For each case, you should output ¡°Case k: ¡± first, where k indicates the case number and counts from one. Then output ¡°Yes¡± or ¡°No¡±.

 

Sample Input
6 34567TJQKA2222BRKKKA 45678AAQQJJTT3339 45566778889994TJQ 3456789TJQ2222BRKKK3 456789TJQKAAA3344 5566778899TTJJQQA 3456789TJQKKK4BR2222 456789TJQKA9TTJJQ AAA3334556677889Q 33445566778899JJJ222 B2AAAKQQTT3456789 RKKKAQQTT3456789J BR33336666KKKK222245 TTTT7777445JJQQAA 99998888455QQJJAA AAAKKKQQQJJJTTT98765 BR234555666777888 222333444999TJQKA
 

Sample Output
Case 1: Yes Case 2: Yes Case 3: No Case 4: Yes Case 5: No Case 6: Yes
 

Hint
A lot of test cases, pay attention to the efficiency of your program.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-16 15:26:16, Gzip enabled