luogu#P5013. 水の斗牛
水の斗牛
Background
Newbie dragged , , and a group of big shots from the computer lab to play Bullfight!!
Problem Description
There are now people playing Bullfight. A total of rounds are played. In each round, three people participate, and everyone starts with a score of .
For convenience, this problem makes some small changes to the basic rules of Bullfight. The detailed rules are as follows.
1. Basic Rules
At the start of each Bullfight round, each player receives cards.
Each card is either an integer from to or A (which represents ).
Each card has a suit: a for spades, b for hearts, c for clubs, and d for diamonds.
2. Hand Types
Among the five cards, except for Bomb and No Bull, every hand is divided into two parts: Bull and Points.
- The Bull part consists of either three cards with the same rank (Iron Plate), or three cards whose ranks sum to a multiple of .
- The Points part consists of the remaining two cards. The points of a hand is the remainder of the sum of these two cards modulo .
The hand types are:
(1) Bomb: four cards with the same rank.
(2) Bull Bull: the points is exactly .
(3) Bull: the points is not , and the value of the points equals the bull number. For example, if the points is , then this hand is called Bull Five.
(4) No Bull: there do not exist three cards whose ranks are all the same, or whose rank sum is a multiple of .
3. Hand Ranking Rules
Bomb Bull Bull Bull Nine Bull Eight Bull Two Bull One No Bull.
If both sides have Bomb, the Bomb with the larger rank is larger.
If the bull number is the same and only one side has an Iron Plate, the one with an Iron Plate is larger.
If the bull number is the same and both sides have an Iron Plate, the Iron Plate with the larger rank is larger.
If the bull number is the same and neither side has an Iron Plate, or both sides have No Bull, compare the highest-rank card in each hand. The side with the larger highest card is larger. If the highest card ranks are equal, compare suits: spades hearts clubs diamonds.
4. Scoring
The base score of a hand is , meaning each player bets points.
For any two players, after comparing their hand types, we take the larger hand type (between the two) to determine the score multiplier for the gain/loss. The rules are:
(1) Bomb: base score .
(2) Bull Bull: base score .
(3) Bull Seven / Bull Eight / Bull Nine: base score .
(4) Bull Six to Bull One: base score.
(5) No Bull: base score.
(6) Iron Plate: after computing the hand-type score, multiply by based on that score. Note that the Iron Plate multiplier is not applied together with Bomb.
Scoring is done pairwise. That is, for three players A, B, and C, we first compute the score gain/loss between A and B, then between A and C, and finally between B and C.
Now assume all players are smart enough, meaning every player will always play the largest possible hand type from the cards in their hand. wants to know, after these rounds, the final score of each player.
Input Format
The first line contains three integers . Here is the test point index, which may be helpful for partial scoring. In the samples, the test point index is .
The next lines each contain a string of length less than consisting only of letters (uppercase/lowercase) and digits, representing a player name.
Then follow groups. Each group has six lines, and can be viewed as three identical parts:
- The first line contains a string: the player name.
- The second line contains five strings: the player’s five cards. For each string, the first character is the suit, and the remaining characters represent the rank.
Output Format
Output lines. Each line contains a string and an integer, separated by a space, representing a player and their final score.
Please output in the same order as the player names are given in the input.
0 2 3
CYJian
JerryC
Justin
CYJian
a10 b10 c10 d10 a9
JerryC
cA b2 c3 d4 d5
Justin
aA bA dA a4 c6
CYJian
aA b2 c3 d4 a5
JerryC
bA c2 d3 a4 b5
Justin
cA d2 a3 c4 c5
CYJian 220
JerryC -160
Justin -60
0 3 4
CYJian
JerryC
Samcompu
Hsl2363
CYJian
a2 b5 c8 d4 aA
Samcompu
a2 bA c3 a4 c5
JerryC
aA b2 c7 c4 c6
Hsl2363
aA bA cA dA a10
Samcompu
a2 b2 c2 d2 b10
JerryC
a3 b3 c3 d3 c10
Hsl2363
a5 c6 d8 a9 b9
JerryC
b6 b2 c9 a7 d2
CYJian
b5 d5 c5 a6 d9
CYJian 120
JerryC 150
Samcompu -60
Hsl2363 -210
Hint
Explanation for Sample 1.
In the first round, the hand types are:
: Bomb
: Bull Five
: Iron Plate Bull Bull
So gains points, loses points, and loses points.
In the second round, everyone has Bull Five, but has the spade five, has the heart five, and has the club five. So gains points, does not change, and loses points.
Constraints:
| Test Point Index | Special Property | ||
|---|---|---|---|
| Property 4 | |||
| - | Property 1 | ||
| - | Property 2 | ||
| - | Property 3 | ||
| - | Property 5 | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | Property 5, | ||
Property 1: It is guaranteed that everyone has a Bomb.
Property 2: It is guaranteed that all suits in each hand are the same.
Property 3: It is guaranteed that all ranks in each hand are different.
Property 4: It is guaranteed that the testdata is handcrafted.
Property 5: It is guaranteed that the testdata is randomly generated.
It is guaranteed that there are no repeated cards within any round.
It is guaranteed that every player has a unique name.
It is guaranteed that the problem setter is .
It is guaranteed that the data has no bugs.
It is not guaranteed that someone can solve it.
It is not guaranteed that the code for this problem is very long.
Translated by ChatGPT 5