409244: GYM103466 G Poker Game

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Poker Gametime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard output

Five desperados are playing a poker game.

The hot dealer Myla organizes a $$$n$$$-round competition. Before the game, each player has $$$100$$$ pots corresponding to a certain amount of money. A penniless player, whose pot is zero, will be disqualified and is not allowed to play anymore.

As in most poker games, the deck is a standard $$$52$$$-card deck containing no jokers. Instead of a fair shuffle of the cards, Myla has decided the order of cards on ahead of time.

Now the game begins.

During every round, play begins with each player being dealt two private cards face down, with the first non-disqualified player receiving the first and the second cards, and the second non-disqualified player receiving the third and fourth cards, and etcetera. These cards are the players' hole cards.

The hand begins with a pre-flop betting round in which all players make decisions one by one in order. Each player may fold, which is to drop out of the hand and give up in this round, or call, which is to call for a bet of $$$5$$$ pots.

After the pre-flop betting round, the hot dealer Myla deals a flop: three face-up community cards. The flop is followed by a second betting round similarly. Each player may fold, which is to drop out of the hand losing any bets they have already made, or call, which is to call for a bet of $$$5$$$ pots.

After the flop betting round ends, two more community cards are dealt, followed by a third betting round as before.

If a player wants to remain after the final betting round, he must call for $$$15$$$ pots in total. But there is one exception. If a player, before the pre-flop betting round, has less than $$$15$$$ pots, he is not allowed to take part in even the pre-flop betting round unless he declares himself all in in the pre-flop betting round betting his entire stack. If a player goes all-in, he does not need to bet anymore and will be remained after the final betting round no matter whether he would be willing or not.

At any time during a round, if only one player remains and all other players have folded, the remaining player is awarded the pot and is not required to show his hole cards. If two or more players remain after the final betting round, a showdown occurs. On the showdown, each player plays the best poker hand they can make from the seven cards comprising their two-hole cards and the five community cards.

The player who has the best hand takes all the pots called in betting rounds. If the best hand is shared by more than one player, then one in the last order takes all the pots.

Following list shows the possible hand values in increasing order.

  • Highcard Simple value of the card.
  • Pair Two cards with the same value.
  • Three of a kind Three cards with the same value.
  • Straight Sequence of $$$5$$$ cards in increasing value, where Ace can only be the first card preceding 2 or the last one following up King. All possible Straights are listed as follows: A2345, 23456, 34567, 45678, 56789, 6789T, 789TJ, 89TJQ, 9TJQK and TJQKA. Note that T is the abbreviation for 10.
  • Flush $$$5$$$ cards of the same suit.

The card's numerical rank is also important. The card rank with highest first is given by A K Q J T 9 8 7 6 5 4 3 2 (A, only in the case of Straight A2345).

If several players share a common hand value, the rank of the critical card higher, the hand better. In a HighCard, the critical card is the one with the highest rank. In a Pair, the critical card is the one appearing in a pair with the highest rank. If the hand is Three of a kind, the card in the triple is critical. The card with the highest rank in a Straight or a Flush is the critical card, but note that 5 is the critical card in Straight A2345 but Ace is the critical one in Straight TJQKA. Please pay attention to this case and note that if cards in A2345 are of the same suit, it should be regarded as Flush or the so-called Straight Flush, and the critical card here is the Ace.

Now, let's talk about these desperados. All of them were professional ICPC competitors and they all know how to design a good strategy.

The first one is John-zeng Montagu. If his pot is less than $$$15$$$, he folds in the very beginning. He calls in the pre-flop betting round only if his hole cards are of the same suit. He always calls in the flop betting round and calls in the third betting round if the best poker hand he can make is not worse than Pair.

The second player is Brain-chen Molony. In the pre-flop betting round, he calls or even goes all-in if he has at least $$$15$$$ pots or his hole cards are the double Aces. He calls in the flop betting round if the given $$$5$$$ cards are not worse than Pair, or he can make it Straight or Flush with one more ideal card. He calls in the third betting round unless there are at least four community cards with the same suit.

The third player is Wild-tang-Bill Hickok. He calls or even goes all-in, in the pre-flop betting round, if he holds at least one Ace or the value difference between his hole cards is less than three. In the flop betting round, he folds when two of the community cards share the same value but the value does not appear in his hole cards. He always calls in the third betting round.

The fourth player is Kerry-wu Packer. In the pre-flop betting round, he calls or even goes all-in if he holds a card whose rank is higher than Jack (including Ace). He calls in the flop betting round if he holds a card higher than all community cards, or he can pair a hole card up with the highest community card. In the third betting round, he calls if the best hand is not worse than Three of a kind, or at least Pair and the rank (of the Pair) is higher than the rank of the third-highest community card (counted with multiplicity).

The last player is Archie-zou Karas. In the pre-flop betting round, he calls or even goes all-in only if there is only one another player called. Then he always calls in the second and the third round.

Input

The first line contains an integer $$$n~(1\le n\le 1\,000)$$$ indicating the total number of rounds organized.

Each of the following $$$n$$$ lines contains $$$15$$$ integers describing all cards dealt by the hot dealer Myla in order. Note that the hot dealer can deal less than fifteen cards and remain some in her hand since some players may be disqualified. The numbers from $$$1$$$ to $$$13$$$, from $$$14$$$ to $$$26$$$, from $$$27$$$ to $$$39$$$ and from $$$40$$$ to $$$52$$$ correspond to cards in different suits from Ace, 2 to 10, Jack, Queen and King.

Output

Output five lines, each of which contains a number indicating the final pot of the corresponding player.

ExamplesInput
2
1 2 8 10 3 11 15 12 14 27 42 43 45 48 13
14 2 8 10 3 11 5 23 1 27 42 43 13 45 48
Output
90
90
100
115
105
Input
5
9 5 19 35 30 42 18 8 21 51 16 26 32 29 49
17 50 13 7 37 21 25 31 28 18 30 27 24 16 15
31 38 52 46 1 29 41 12 39 24 10 45 13 22 42
8 10 33 18 39 49 29 43 51 2 35 19 27 41 12
48 13 33 39 30 47 32 24 12 9 42 1 18 41 51
Output
65
115
115
100
105
Input
5
51 31 17 50 24 15 25 20 22 16 44 6 19 39 28
34 1 21 10 31 15 35 8 27 51 32 23 48 24 29
39 18 27 14 31 2 35 51 44 21 24 6 43 16 19
9 44 4 19 35 47 15 51 25 20 40 8 21 6 7
49 35 11 12 44 29 22 9 16 13 4 17 32 25 7
Output
100
125
115
75
85
Input
5
16 41 30 6 5 39 22 1 29 42 32 49 40 27 21
39 14 32 48 6 37 23 35 13 52 43 2 24 38 45
49 42 38 18 47 52 30 15 16 1 26 31 28 6 40
47 31 22 45 49 46 36 17 35 48 38 33 13 16 20
41 17 9 34 25 21 8 18 22 24 4 20 26 15 42
Output
90
80
100
115
115
Input
5
26 38 46 4 52 15 51 7 1 30 5 3 33 47 34
22 7 15 9 5 29 32 23 30 25 33 2 1 50 4
22 44 31 33 32 39 26 5 21 15 48 2 52 37 13
21 50 12 7 43 26 32 28 42 30 20 9 35 47 8
38 12 4 33 10 25 50 37 46 36 6 40 29 48 5
Output
100
65
100
120
115
Input
5
32 51 43 23 30 17 36 37 48 22 46 41 20 1 42
49 29 40 4 19 46 13 39 8 12 47 38 16 32 34
37 34 45 36 10 26 33 21 46 35 39 13 41 27 19
51 15 42 35 27 52 18 1 44 37 26 39 33 32 8
31 50 52 24 37 17 26 2 20 13 1 38 9 49 51
Output
85
105
110
100
100

加入题单

算法标签: