#P4010. Calculating Show Hand Winning Probability

    ID: 17258 Type: Default 1000ms 256MiB

Calculating Show Hand Winning Probability

Calculating Show Hand Winning Probability

In the card game Show Hand (also known as Shao Ha), a deck of 52 cards (from A to K in four suits: spades, hearts, clubs, diamonds) is used. Each player eventually obtains 5 cards and the player with the best hand wins the round according to the following hand rankings (from highest to lowest):

  1. Straight Flush: Five cards of the same suit in consecutive order. Example: \( Q\spadesuit, J\spadesuit, 10\spadesuit, 9\spadesuit, 8\spadesuit \).
  2. Four of a Kind: Four cards of the same rank. Example: \( 10\clubsuit, 10\diamondsuit, 10\heartsuit, 10\spadesuit, 9\heartsuit \).
  3. Full House: Three cards of one rank and a pair of another rank. Example: \( 8\clubsuit, 8\diamondsuit, 8\spadesuit, K\heartsuit, K\spadesuit \).
  4. Flush: Five cards of the same suit. Example: \( A\spadesuit, K\spadesuit, 10\spadesuit, 9\spadesuit, 8\spadesuit \).
  5. Straight: Five cards in a consecutive order. Example: \( K\diamondsuit, Q\heartsuit, J\spadesuit, 10\diamondsuit, 9\diamondsuit \).
  6. Three of a Kind: Three cards of the same rank. Example: \( J\clubsuit, J\heartsuit, J\spadesuit, K\diamondsuit, 9\spadesuit \).
  7. Two Pairs: Two different pairs. Example: \( A\clubsuit, A\diamondsuit, 8\heartsuit, 8\spadesuit, Q\spadesuit \).
  8. One Pair: A single pair. Example: \( 9\heartsuit, 9\spadesuit, A\clubsuit, J\spadesuit, 8\heartsuit \).
  9. Zilch: None of the above combinations; the ranking is decided by the individual card values and suits. Example: \( A\diamondsuit, Q\diamondsuit, J\spadesuit, 9\clubsuit, 8\clubsuit \).

If two hands have the same category, the tie is broken by comparing the key card ranks (and their suits, according to the order spades > hearts > clubs > diamonds) as specified in the examples below:

  • Example 1: \( Q\diamondsuit, J\diamondsuit, 10\diamondsuit, 9\diamondsuit, 8\diamondsuit \) beats \( 8\clubsuit, 8\heartsuit, 8\spadesuit, K\heartsuit, K\spadesuit \) because a Straight Flush beats a Full House.
  • Example 2: \( 9\clubsuit, 9\diamondsuit, 9\spadesuit, Q\heartsuit, Q\spadesuit \) beats \( 8\clubsuit, 8\diamondsuit, 8\spadesuit, K\heartsuit, K\spadesuit \) since 9 > 8 in the triple.
  • Example 3: \( A\clubsuit, A\diamondsuit, 8\heartsuit, 8\spadesuit, Q\spadesuit \) beats \( A\spadesuit, A\heartsuit, 7\heartsuit, 7\spadesuit, K\spadesuit \) because after comparing the largest pair, the second pair 8 > 7.
  • Example 4: \( A\spadesuit, Q\spadesuit, J\heartsuit, 9\heartsuit, 8\heartsuit \) beats \( A\diamondsuit, Q\diamondsuit, J\spadesuit, 9\clubsuit, 8\clubsuit \) since when all ranks are equal the suit of the highest card is compared.
  • Example 5: \( 4\spadesuit, 4\heartsuit, A\diamondsuit, Q\diamondsuit, 5\diamondsuit \) beats \( 4\clubsuit, 4\diamondsuit, A\spadesuit, Q\spadesuit, 5\spadesuit \) because the suit of the pair (4\spadesuit vs 4\clubsuit) gives the advantage.

In a round of Show Hand, after all players have five cards, the winner is determined by comparing hands. Little Y wants to know, based on the five cards he has, what his winning probability is if his opponent’s hand is chosen uniformly at random from the remaining deck.

Your task is to compute the winning probability of the given hand. Assume the input is a single line containing 5 card representations separated by spaces. Each card is represented by its rank followed by its suit. Ranks are one of A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2 and suits are one of S (spades), H (hearts), C (clubs), D (diamonds). The winning probability should be output as a percentage with 6 decimal places. Note that ties do not count as wins.

inputFormat

The input consists of a single line with 5 space‐separated cards. Each card is represented by a rank and a suit (e.g., "AS" stands for Ace of Spades, "TD" stands for Ten of Diamonds).

outputFormat

Output a single line: the winning probability (as a percentage) with 6 decimal places.

sample

AS KS QS JS TS
100.000000