Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
Language:
Double Patience
Time Limit: 3000MSMemory Limit: 65536K
Total Submissions: 795Accepted: 396
Case Time Limit: 1000MSSpecial Judge

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 pairswith equal probability.

For example, if the top cards are KS, KH, KD, 9H, 8S, 8D, 7C, 7D, and 6H, he removes any particular pair of (KS, KH), (KS, KD), (KH, KD), (8S, 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 strategyis 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.

Input

The input contains 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 as '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 as '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.

Output

Output one real number - the probability that George wins the game if he plays randomly. Your answer must be accurate up to 10-6.

Sample Input

AS 9S 6C KS
JC QH AC KH
7S QD JD KD
QS TS JS 9H
6D TD AD 8S
QC TH KC 8D
8C 9D TC 7C
9C 7H JH 7D
8H 6S AH 6H

Sample Output

0.589314

Source

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator