#P1837. Winning Probability of a Single‐Player Card Game
Winning Probability of a Single‐Player Card Game
Winning Probability of a Single‐Player Card Game
This problem asks you to compute the probability that a player wins a single‐player card game played with 36 cards arranged into 9 piles, each containing 4 cards face up. In one move the player may choose any two different piles whose top cards have the same rank (for example, 10♠ and 10♣) and remove both top cards from their piles. The game is won if eventually all cards are removed; otherwise, the game is lost.
George uses the following simple strategy: if at any point there are several valid moves, he chooses one uniformly at random. Your task is to compute the probability that George wins the game if he always selects a valid move at random among all available moves.
Notes:
- The card codes are given in a compact notation. For example, "10S" denotes the 10 of spades, "KH" the king of hearts. (A card code consists of a rank followed by a suit letter. The rank is one of {A,2,3,...,10,J,Q,K}.)
- In the input each pile is given on a separate line containing 4 space‐separated card codes. The cards in each line are given from the bottom to the top. Thus, the last card in each line is the top card available in that pile.
- If there is no pair of piles whose top cards have the same rank, the game ends. If at that moment all piles are empty the player wins; otherwise the player loses.
- If there is at least one valid pair, the player selects one of these pairs uniformly at random. Then the top cards of the two selected piles are removed (exposing the next card in those piles, if any) and the process repeats.
The game procedure is as follows:
inputFormat
The input consists of 9 lines. Each line contains 4 space‐separated card codes describing one pile (from bottom to top).
outputFormat
Output a single floating–point number indicating the probability that the player wins the game following George's random move selection strategy. It is recommended to output the result with at least 6 digits after the decimal point.
sample
KS KH KD KC
9S 9H 9D 9C
8S 8H 8D 8C
7S 7H 7D 7C
6S 6H 6D 6C
5S 5H 5D 5C
4S 4H 4D 4C
3S 3H 3D 3C
2S 2H 2D 2C
0.000000