luogu#P5013. 水の斗牛

水の斗牛

Background

Newbie CYJian{\rm CYJian} dragged JerryC{\rm JerryC}, Justin{\rm Justin}, and a group of big shots from the computer lab to play Bullfight!!

Problem Description

There are now NN people playing Bullfight. A total of TT rounds are played. In each round, three people participate, and everyone starts with a score of 00.

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 55 cards.

Each card is either an integer from 22 to 1010 or A (which represents 11).

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 1010.
  • 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 1010.

The hand types are:

(1) Bomb: four cards with the same rank.

(2) Bull Bull: the points is exactly 00.

(3) Bull: the points is not 00, and the value of the points equals the bull number. For example, if the points is 55, 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 1010.

3. Hand Ranking Rules

Bomb >> Bull Bull >> Bull Nine >> Bull Eight >> \cdots >> 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 1010, meaning each player bets 1010 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 ×10\times 10.

(2) Bull Bull: base score ×3\times 3.

(3) Bull Seven / Bull Eight / Bull Nine: base score ×2\times 2.

(4) Bull Six to Bull One: base score.

(5) No Bull: base score.

(6) Iron Plate: after computing the hand-type score, multiply by 22 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. CYJian{\rm CYJian} wants to know, after these TT rounds, the final score of each player.

Input Format

The first line contains three integers id,T,Nid, T, N. Here idid is the test point index, which may be helpful for partial scoring. In the samples, the test point index is 00.

The next NN lines each contain a string of length less than 1111 consisting only of letters (uppercase/lowercase) and digits, representing a player name.

Then follow TT 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 NN 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:

CYJian{\rm CYJian}: Bomb

JerryC{\rm JerryC}: Bull Five

Justin{\rm Justin}: Iron Plate Bull Bull

So CYJian{\rm CYJian} gains 200200 points, JerryC{\rm JerryC} loses 160160 points, and Justin{\rm Justin} loses 4040 points.

In the second round, everyone has Bull Five, but CYJian{\rm CYJian} has the spade five, JerryC{\rm JerryC} has the heart five, and Justin{\rm Justin} has the club five. So CYJian{\rm CYJian} gains 2020 points, JerryC{\rm JerryC} does not change, and Justin{\rm Justin} loses 2020 points.

Constraints:

Test Point Index TT NN Special Property
11 00 33 Property 4
22 55
33-44 Property 1
55-66 Property 2
77-88 Property 3
99-1010 Property 5
1111-1212 1010
1313-1414 100100
1515-1616 10001000
1717-1818 1000010000
1919-2020 100000100000 Property 5, 1.5s1.5\text{s}

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 CYJian{\rm CYJian}.

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