P28905 [洛谷] Water Bullfight
提高
题目描述

Problem Background

The novice ${\rm CYJian}$ has gathered ${\rm JerryC}$, ${\rm Justin}$, and other powerhouse programmers in the computer room to play Bullfight!

Problem Description

There are a total of $N$ players participating in Bullfight, playing $T$ rounds, with three players in each round, and everyone starts with a score of 0.

For convenience, the basic rules of Bullfight have been slightly modified as follows:

1. Basic Rules

At the beginning of each round of Bullfight, each player receives 5 cards.

Each card is an integer between 2 and 10 or an 'A' (representing 1).

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 bombs and no-bull hands, all other hands are divided into two parts: bull and points. The bull includes three cards with the same points (iron plate) or three cards whose points sum to a multiple of 10, and the points include the remaining two cards, with the points of a hand being the remainder of these two cards modulo 10.

1) Bomb: Four cards with the same points.
2) Bull-Bull: Points exactly 0.
3) Bull: Points not 0, with the points and bull number being the same. For example, if the points are 5, this hand is called Bull-Five.
4) No-Bull: There are no three cards with the same points or whose points sum to a multiple of 10.

3. Hand Comparison

Bomb > Bull-Bull > Bull-Nine > Bull-Eight > ... > Bull-Two > Bull-One > No-Bull

When both have bombs, the one with the higher bomb points wins.

With the same bull number and only one having an iron plate, the one with the iron plate wins.

With the same bull number and both having iron plates, the one with the higher iron plate points wins.

With the same bull number and neither having an iron plate or both having no-bull, we compare the highest point card in each hand; the one with the higher point wins. If the highest point cards are the same, the one with the higher suit wins, with suits ordered as spades > hearts > clubs > diamonds.

4. Scoring

The base score for each round is 10, meaning each player bets 10 points.

For the two players, after comparing their hand types, we choose the hand type of the player with the higher hand type to calculate the doubled points. Specifically:

1) Bomb: Base score × 10.
2) Bull-Bull: Base score × 3.
3) Bull-Seven/Bull-Eight/Bull-Nine: Base score × 2.
4) Bull-Six to Bull-One: Base score.
5) No-Bull: Base score.
6) Iron Plate: After calculating the hand type score, double it on top of the hand type score. Note that iron plate doubling does not occur with bombs.

We score by pairwise comparison, meaning for three players A, B, C, we first calculate the score between A and B, then between A and C, and finally between B and C.

We assume all players are smart enough to always play the highest hand type from their cards. ${\rm CYJian}$ wants to know the final scores of each player after $T$ rounds.

Input and Output Formats

Input Format

The first line contains three integers: id, T, N. id represents the test point number, which may be helpful for partial scores. The sample test point number is 0.

The next N lines, each containing a string of less than 11 characters consisting of uppercase and lowercase letters and digits, represent player names.

The next T groups, each consisting of six lines, can be divided into three identical parts:

The first line is a string representing the player's name.
The second line contains five strings representing the player's hand. Each string's first character represents the suit, and the remaining characters represent the card's size.

Output Format

A total of N lines, each containing a string and a number separated by a space, representing a player and their final score.

Output in the order of player names as input.

Sample Input and Output

Input Sample #1

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

Output Sample #1

CYJian 220
JerryC -160
Justin -60

Input Sample #2

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

Output Sample #2

CYJian 120
JerryC 150
Samcompu -60
Hsl2363 -210

Notes

Sample 1 Explanation:

In the first round, the players' hand types are as follows:

${\rm CYJian}$: Bomb
${\rm JerryC}$: Bull-Five
${\rm Justin}$: Iron Plate Bull-Bull

So ${\rm CYJian}$ gains 200 points, ${\rm JerryC}$ loses 160 points, and ${\rm Justin}$ loses 40 points.

In the second round, everyone has Bull-Five, but ${\rm CYJian}$ has the spade five, ${\rm JerryC}$ has the heart five, and ${\rm Justin}$ has the club five, so ${\rm CYJian}$ gains 20 points, ${\rm JerryC}$ remains unchanged, and ${\rm Justin}$ loses 20 points.

Data Range:

Test Point Number $T$ $N$ Special Properties
1 0 3 Property 4
2 5 5 Property 4
3-4 5 5 Property 1
5-6 5 5 Property 2
7-8 5 5 Property 3
9-10 5 5 Property 5
11-12 10 10 Property 5
13-14 100 100 Property 5
15-16 1000 1000 Property 5
17-18 10000 10000 Property 5
19-20 100000 100000 Property 5, 1.5s

Property 1: All players have bombs.
Property 2: Each hand has the same suit.
Property 3: Each hand has all different numbers.
Property 4: Data is manually crafted.
Property 5: Data is randomly generated.

Each round guarantees no duplicate cards.
Each player's name is unique.
The problem author is ${\rm CYJian}$.
The data is bug-free.
It is not guaranteed that no one can solve it.
It is not guaranteed that the code for this problem is short.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
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