Double Patience
Time Limit:3000 MS |
|
Memory Limit:Unknown |
|
64bit IO Format:% Lld & % llu |
Submit Status Description Double Patience is a single player game played with a standard 36-card deck. The cards are shuffled and laid down on a table in 9 piles of 4 cards each, faces up. After the cards are laid down, the player makes turns. in a turn he can take top cards of the same rank from any two piles and remove them. if there are several possibilities, the player can choose any one. if all the cards are removed from the table, the player wins the game, if some cards are still on the table and there are no valid moves, the player loses. George enjoys playing this patience. but when there are several possibilities to remove two cards, he doesn't know which one to choose. george doesn't want to think much, so in such case he just chooses a random pair from among the possible variants and removes it. george chooses among all possible pairs with equal probability. For example, if the top cards are KS, KH, KD, 9 H, 8 S, 8D, 7C, 7D, and 6 H, he removes any particle pair of (KS, KH), (KS, KD), (KH, KD), (8 S, 8D), and (7C, 7D) with the equal probability of 1/5. Once George's friend Andrew came to see him and noticed that he sometimes doesn't act optimally. george argued, that it is not important-the probability of winning any given patience with his strategy is large enough. Help George to prove his statement-given the cards on the table in the beginning of the game, find out what is the probability of George winning the game if he acts as described. InputThe input file contains several test cases, each of them consists of nine lines. each line contains the description of four cards that form a pile in the beginning of the game, from the bottom card to the top one. Each card is described with two characters: one for rank, one for suit. Ranks are denoted'6'For six ,'7'For seven ,'8'For eight ,'9'For nine ,'T'For ten ,'J'For jack ,'Q'For queen ,'K'For king, and'A'For ace. Suits are denoted'S'For spades ,'C'For clubs ,'D'For diamonds, and'H'For hearts. For example ,''KS"Denotes the king of spades. Card descriptions are separated from each other by one space. OutputFor each test case, output a line with one real number-the probability that George wins the game if he plays randomly. Your answer must be accurate up to 10-6. Sample InputAS 9S 6C KSJC QH AC KH7S QD JD KDQS TS JS 9H6D TD AD 8SQC TH KC 8D8C 9D TC 7C9C 7H JH 7D8H 6S AH 6H Sample Output0.589314 Source Root: aoapc ii: Beginning Algorithm Contests (Second Edition) (Rujia Liu): Chapter 10. Maths: ExamplesSubmit Status |
|