eolymp
bolt
Try our new interface for solving problems

Tichu

Tichu is a card game played by four players. The players sit around a square table, and each player forms a team with the person sitting opposite him or her. The game is played with a standard deck of cards and four additional special cards. The basic rule of the game is as follows: the player who won the last trick can start a new trick with any legal combination of cards. Then, in turn, each next player can either pass or play the same combination of cards, but with a higher value. This continues until everyone passes, and at that point the player who played the last combination wins the trick and can start a new trick. The main goal is to get rid of all of your cards as soon as possible. These basic rules make it a good tactic to combine the cards in such a way that they can be played in as few combinations as possible. For simplicity we consider here a slightly modified version of the game. We ignore the special cards, so that leaves a standard deck of \textbf{52} cards, ranging over the values \textbf{2} to Ace and over the suits hearts, diamonds, clubs, and spades. The suits are indicated by the lowercase letters \textbf{h}, \textbf{d}, \textbf{c}, and \textbf{s}, while the values are indicated in increasing order by \textbf{2--9}, \textbf{T}, \textbf{J}, \textbf{Q}, \textbf{K}, \textbf{A}. The following list is a complete set of legal combinations: \begin{itemize} \item any single card; \item a pair of cards of the same value; \item three cards of the same value; \item four cards of the same value; \item a full house, that is, three cards of the same value and two cards of another, same value, for example \textbf{444KK}; \item a straight of length at least five, that is, at least five cards of consecutive increasing values, for example \textbf{89TJQK}. \end{itemize} In this problem, your task is to determine the minimum number of combinations that your hand of \textbf{13} cards can be partitioned into. \InputFile On the first line a positive integer: the number of test cases, at most \textbf{100}. After that per test case: \begin{itemize} \item one line that describes your hand of \textbf{13} cards. The card descriptions are separated by single spaces. A card is described by two characters: the value followed by the suit. All cards in your hand are different. \end{itemize} \OutputFile Per test case: \begin{itemize} \item one line containing an integer n: the minimum number of combinations that your hand can be partitioned into. \item \textbf{n} lines that describe a minimal set of combinations of cards from your hand. Each line should contain the cards in one legal combination, in the same format as in the input. All cards from your hand must occur exactly once in one of the combinations. No specific ordering of the combinations or the cards within a combination is required. \end{itemize}
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
2
2h 3c 4d 5d 6s Th Qc Qs Ad Tc Ts 9c 9d
2h 3h 4h 5h 6d 7s 8h 8d 8c 8s 9c Td Js
Çıxış verilənləri #1
4
2h 3c 4d 5d 6s
Th Ts Tc Qc Qs
9d 9c
Ad
2
2h 3h 4h 5h 6d 7s 8d 9c Td Js
8h 8s 8c
Mənbə NWERC 2011 - The 2011 ACM Northwestern Europe Programming Contest