编程介的小学生 2020-02-16 02:03 采纳率: 20.5%
浏览 132

Fight the Landlord 的编写设计

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序