CF1932D.Card Game

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Two players are playing an online card game. The game is played using a 32-card deck. Each card has a suit and a rank. There are four suits: clubs, diamonds, hearts, and spades. We will encode them with characters 'C', 'D', 'H', and 'S', respectively. And there are 8 ranks, in increasing order: '2', '3', '4', '5', '6', '7', '8', '9'.

Each card is denoted by two letters: its rank and its suit. For example, the 8 of Hearts is denoted as 8H.

At the beginning of the game, one suit is chosen as the trump suit.

In each round, players make moves like this: the first player places one of his cards on the table, and the second player must beat this card with one of their cards. After that, both cards are moved to the discard pile.

A card can beat another card if both cards have the same suit and the first card has a higher rank than the second. For example, 8S can beat 4S. Additionally, a trump card can beat any non-trump card, regardless of the rank of the cards, for example, if the trump suit is clubs ('C'), then 3C can beat 9D. Note that trump cards can be beaten only by the trump cards of higher rank.

There were nn rounds played in the game, so the discard pile now contains 2n2n cards. You want to reconstruct the rounds played in the game, but the cards in the discard pile are shuffled. Find any possible sequence of nn rounds that might have been played in the game.

两名玩家正在玩一款在线纸牌游戏。该游戏使用一副 32 张牌的牌组。每张牌具有一个花色和一个点数。共有四种花色:梅花(clubs)、方块(diamonds)、红桃(hearts)和黑桃(spades),我们分别用字符 'C'、'D'、'H' 和 'S' 编码。共有 8 个点数,按升序排列为:'2'、'3'、'4'、'5'、'6'、'7'、'8'、'9'。

每张牌由两个字符表示:其点数和其花色。例如,红桃 8 表示为 8H。

游戏开始时,会选定一种花色作为将牌(trump suit)。

在每一轮中,玩家按如下方式出牌:先手玩家将其一张手牌置于桌面,后手玩家必须用其一张手牌“击败”该牌。随后,这两张牌均被移入弃牌堆。

一张牌可以击败另一张牌,当且仅当满足以下条件之一:

  • 两张牌花色相同,且前者的点数高于后者。例如,8S 可以击败 4S;
  • 前者为将牌而后者非将牌(此时无论点数大小如何,前者均可击败后者)。例如,若将牌花色为梅花('C'),则 3C 可以击败 9D。
    注意:将牌仅能被点数更高的将牌所击败。

游戏中共进行了 nn 轮,因此弃牌堆中现在包含 2n2n 张牌。你希望还原出游戏实际进行的各轮出牌顺序,但弃牌堆中的牌已被打乱。请找出任意一种可能的、由 nn 轮组成的出牌序列,使得该序列与弃牌堆中的牌集一致。

输入格式

The first line contains integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. Then tt test cases follow.

The first line of a test case contains the integer number nn (1≤n≤161\le n\le 16).

The second line of a test case contains one character, the trump suit. It is one of "CDHS".

The third line of a test case contains the description of 2n2n cards. Each card is described by a two-character string, the first character is the rank of the card, which is one of "23456789", and the second one is the suit of the card, which is one of "CDHS". All cards are different.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤161\le n\le 16)。

每个测试用例的第二行包含一个字符,表示王牌花色。该字符为 "CDHS" 中的一个。

每个测试用例的第三行包含 2n2n 张牌的描述。每张牌由一个长度为 2 的字符串描述:第一个字符为牌的点数,属于 "23456789" 中的一个;第二个字符为牌的花色,属于 "CDHS" 中的一个。所有牌互不相同。

输出格式

For each test case print the answer to it:

  • Print nn lines. In each line, print the description of two cards, in the same format as in the input: the first card that was played by the first player, and then the card that was used by the second player to beat it.
  • If there is no solution, print a single line "IMPOSSIBLE".

If there are multiple solutions, print any of them.

对每个测试用例,输出其答案:

  • 输出 nn 行。在每一行中,按输入中的相同格式输出两张牌的描述:第一张为第一位玩家打出的牌,第二张为第二位玩家用来击败它的牌。
  • 若无解,则输出单独一行 "IMPOSSIBLE"。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    8
    3
    S
    3C 9S 4C 6D 3S 7S
    2
    C
    3S 5D 9S 6H
    1
    H
    6C 5D
    1
    S
    7S 3S
    1
    H
    9S 9H
    1
    S
    9S 9H
    1
    C
    9D 8H
    2
    C
    9C 9S 6H 8C

    输出#1

    3C 4C
    6D 9S
    3S 7S
    IMPOSSIBLE
    IMPOSSIBLE
    3S 7S
    9S 9H
    9H 9S
    IMPOSSIBLE
    6H 9C
    9S 8C

输入解题思路,AI测评打分。不知道怎么写?

首页