CF1894A.Secret Sport

入门

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Let's consider a game in which two players, A and B, participate. This game is characterized by two positive integers, XX and YY.

The game consists of sets, and each set consists of plays. In each play, exactly one of the players, either A or B, wins. A set ends exactly when one of the players reaches XX wins in the plays of that set. This player is declared the winner of the set. The players play sets until one of them reaches YY wins in the sets. After that, the game ends, and this player is declared the winner of the entire game.

You have just watched a game but didn't notice who was declared the winner. You remember that during the game, nn plays were played, and you know which player won each play. However, you do not know the values of XX and YY. Based on the available information, determine who won the entire game — A or B. If there is not enough information to determine the winner, you should also report it.

我们来考虑一个由两名玩家 A 和 B 参与的游戏。该游戏由两个正整数 XX 和 YY 刻画。

游戏由若干“局”(sets)组成,而每一局又由若干“回合”(plays)组成。在每个回合中,恰好有一名玩家(A 或 B)获胜。当某一名玩家在该局的回合中赢得 XX 次时,该局立即结束;这名玩家即被判定为该局的胜者。玩家们持续进行局的比拼,直到其中一名玩家累计赢得 YY 局为止;此时整个游戏结束,该玩家即被判定为整场游戏的胜者。

你刚刚观看了一场游戏,但未留意最终谁被宣布为整场游戏的胜者。你只记得整场游戏中共进行了 nn 个回合,并且你知道每个回合的胜者是 A 还是 B。然而,你并不知道参数 XX 和 YY 的具体取值。基于这些已知信息,请判断整场游戏的胜者是 A 还是 B;若根据现有信息无法唯一确定胜者,则也需如实报告。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤104)(1 \leq t \leq 10^4) - the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤20)(1 \leq n \leq 20) - the number of plays played during the game.

The second line of each test case contains a string ss of length nn, consisting of characters A\texttt{A} and B\texttt{B}. If si=As_i = \texttt{A}, it means that player A won the ii-th play. If si=Bs_i = \texttt{B}, it means that player B won the ii-th play.

It is guaranteed that the given sequence of plays corresponds to at least one valid game scenario, for some values of XX and YY.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤201 \leq n \leq 20),表示游戏中进行的回合数。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss,由字符 A\texttt{A} 和 B\texttt{B} 组成。若 si=As_i = \texttt{A},表示第 ii 回合由玩家 A 获胜;若 si=Bs_i = \texttt{B},表示第 ii 回合由玩家 B 获胜。

保证所给的回合序列至少对应一个合法的游戏情形(即存在某些 XX 和 YY 的取值使得该序列合法)。

输出格式

For each test case, output:

  • A\texttt{A} — if player A is guaranteed to be the winner of the game.
  • B\texttt{B} — if player B is guaranteed to be the winner of the game.
  • ?\texttt{?} — if it is impossible to determine the winner of the game.

对于每个测试用例,输出:

  • A\texttt{A} — 若玩家 A 必然赢得游戏;
  • B\texttt{B} — 若玩家 B 必然赢得游戏;
  • ?\texttt{?} — 若无法确定游戏的获胜者。

输入输出样例

  • 输入#1

    7
    5
    ABBAA
    3
    BBB
    7
    BBAAABA
    20
    AAAAAAAABBBAABBBBBAB
    1
    A
    13
    AAAABABBABBAB
    7
    BBBAAAA

    输出#1

    A
    B
    A
    B
    A
    B
    A

说明/提示

In the first test case, the game could have been played with parameters X=3X = 3, Y=1Y = 1. The game consisted of 11 set, in which player A won, as they won the first 33 plays. In this scenario, player A is the winner. The game could also have been played with parameters X=1X = 1, Y=3Y = 3. It can be shown that there are no such XX and YY values for which player B would be the winner.

In the second test case, player B won all the plays. It can be easily shown that in this case, player B is guaranteed to be the winner of the game.

In the fourth test case, the game could have been played with parameters X=3X = 3, Y=3Y = 3:

  • In the first set, 33 plays were played: AAA. Player A is declared the winner of the set.
  • In the second set, 33 plays were played: AAA. Player A is declared the winner of the set.
  • In the third set, 55 plays were played: AABBB. Player B is declared the winner of the set.
  • In the fourth set, 55 plays were played: AABBB. Player B is declared the winner of the set.
  • In the fifth set, 44 plays were played: BBAB. Player B is declared the winner of the set.

In total, player B was the first player to win 33 sets. They are declared the winner of the game.

在第一个测试用例中,游戏可能使用参数 X=3X = 3、Y=1Y = 1 进行。整场游戏包含 11 局,其中玩家 A 获胜,因为他们赢得了前 33 次对局。在此情形下,玩家 A 是游戏的获胜者。游戏也可能使用参数 X=1X = 1、Y=3Y = 3 进行。可以证明:不存在任何满足条件的 XX 和 YY 值,使得玩家 B 成为游戏的获胜者。

在第二个测试用例中,玩家 B 赢得了所有对局。容易证明,在此情况下,玩家 B 必然成为游戏的获胜者。

在第四个测试用例中,游戏可能使用参数 X=3X = 3、Y=3Y = 3 进行:

  • 第一局进行了 33 次对局:AAA。玩家 A 被宣布为该局的获胜者。
  • 第二局进行了 33 次对局:AAA。玩家 A 被宣布为该局的获胜者。
  • 第三局进行了 55 次对局:AABBB。玩家 B 被宣布为该局的获胜者。
  • 第四局进行了 55 次对局:AABBB。玩家 B 被宣布为该局的获胜者。
  • 第五局进行了 44 次对局:BBAB。玩家 B 被宣布为该局的获胜者。

总计,玩家 B 是首位赢得 33 局的选手,因此被宣布为整场游戏的获胜者。

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

首页