#P4010. [CTSC2012] 梭哈游戏

[CTSC2012] 梭哈游戏

Description

Xiao Y and Xiao Z have recently become obsessed with a poker game called Show Hand. Show Hand (Chinese: 梭哈, also called 沙蟹) is a poker game played with 5252 cards from AA to KK in spades, hearts, clubs, and diamonds (no jokers).

As with other poker games, the goal in Show Hand is to obtain the highest-ranking hand and win the pot. Each player first places an ante, then receives one hole card, which only the player can see. In the first round after the hole card is dealt, each player receives one upcard (face-up on the table, visible to everyone). The player with the highest upcard acts first and may bet, check, fold, or go all-in (“Show Hand”). Other players may call (if someone has gone all-in, they must also go all-in to call), raise, or fold. A player who folds cannot continue in the game, and the chips they have already bet cannot be retrieved. After an all-in, all players’ hands are immediately filled to 55 cards for the final showdown. The second, third, and fourth rounds proceed in a similar way. Finally, each player compares hand ranks to determine the winner. The player with the highest hand wins.

All 55-card combinations are ranked from highest to lowest as follows:

  1. Straight Flush: five consecutive cards of the same suit. Example: QJ1098Q♦ J♦ 10♦ 9♦ 8♦.

  2. Four of a Kind: four cards of the same rank. Example: 10101010910♣ 10♦ 10♥ 10♠ 9♥.

  3. Full House: three cards of one rank plus a pair of another rank. Example: 888KK8♣ 8♦ 8♠ K♥ K♠.

  4. Flush: five cards of the same suit. Example: AK1098A♠ K♠ 10♠ 9♠ 8♠.

  5. Straight: five consecutive ranks. Example: KQJ109K♦ Q♥ J♠ 10♦ 9♦.

  6. Three of a Kind: three cards of the same rank. Example: JJJK9J♣ J♥ J♠ K♦ 9♠.

  7. Two Pairs: two cards of one rank plus two cards of another rank. Example: AA88QA♣ A♦ 8♥ 8♠ Q♠.

  8. One Pair: two cards of the same rank. Example: 99AJ89♥ 9♠ A♣ J♠ 8♥.

  9. Zilch: none of the above; compare ranks to decide. Example: AQJ98A♦ Q♦ J♠ 9♣ 8♣.

If the hand types are the same, use ranks and then suits to break ties (ranks have priority).

The order of ranks (from high to low) is A>K>Q>J>10>9>8>7>6>5>4>3>2A > K > Q > J > 10 > 9 > 8 > 7 > 6 > 5 > 4 > 3 > 2. Note: when the 55 cards are 5,4,3,2,A5, 4, 3, 2, A, the AA can be treated as the lowest rank. In this case it is still a straight, which is the lowest straight.

The order of suits (from high to low) is spades (♠) > hearts (♥) > clubs (♣) > diamonds (♦).

Examples:

  1. QJ1098>888KKQ♦ J♦ 10♦ 9♦ 8♦ > 8♣ 8♥ 8♠ K♥ K♠ (the former is a Straight Flush, which is higher).

  2. 999QQ>888KK9♣ 9♦ 9♠ Q♥ Q♠ > 8♣ 8♦ 8♠ K♥ K♠ (both are Full Houses; compare the triplets, 99 beats 88).

  3. AA88Q>AA77KA♣ A♦ 8♥ 8♠ Q♠ > A♠ A♥ 7♥ 7♠ K♠ (both are Two Pairs and the higher pair is the same; compare the lower pair, 88 beats 77).

  4. AQJ98>AQJ98A♠ Q♠ J♥ 9♥ 8♥ > A♦ Q♦ J♠ 9♣ 8♣ (both are Zilch with exactly the same ranks; compare the highest card’s suit, A>AA♠ > A♦).

  5. 44AQ5>44AQ54♠ 4♥ A♦ Q♦ 5♦ > 4♣ 4♦ A♠ Q♠ 5♠ (both are One Pair with identical ranks; the pair of 44s is the most significant component, so compare 4>44♠ > 4♣).

During their game, Xiao Y wants to know the current situation in real time—namely, to compute his winning probability based on his current cards. However, his programming skills are limited. Can you help him?

Input Format

The first line contains 11 positive integer NN, the number of cards currently in Xiao Y’s hand.

Each of the next NN lines contains two integers describing one card in Xiao Y’s hand: the first is the rank (11 denotes AA, 1313 denotes KK, 1212 denotes QQ, 1111 denotes JJ), and the second is the suit (11 denotes spades, 22 denotes hearts, 33 denotes clubs, 44 denotes diamonds).

Each of the next N1N - 1 lines contains two integers describing one upcard in Xiao Z’s hand: the first is the rank (11 denotes AA, 1313 denotes KK, 1212 denotes QQ, 1111 denotes JJ), and the second is the suit (11 denotes spades, 22 denotes hearts, 33 denotes clubs, 44 denotes diamonds).

Output Format

Output exactly one line in the form A/B. Here AA and BB are two coprime natural numbers, and A/B is Xiao Y’s probability of winning in the current situation. In particular, if AA is 00, output 0/1.

5
2 1
2 2
2 3
2 4
3 1
1 1
1 2
1 3
3 2
42/43

Hint

Sample Explanation:

Xiao Y’s current hand type is Four of a Kind. If Xiao Z’s hole card is AA♦, he can also make Four of a Kind and win by rank. In all other cases, Xiao Y wins.

Constraints:

  • For 10%10\% of the testdata, N=5N = 5.
  • For 30%30\% of the testdata, 3N53 \leq N \leq 5.
  • For 100%100\% of the testdata, 1N51 \leq N \leq 5.

Translated by ChatGPT 5