CF1681A.Game with Cards

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alice and Bob play a game. Alice has nn cards, the ii-th of them has the integer aia_i written on it. Bob has mm cards, the jj-th of them has the integer bjb_j written on it.

On the first turn of the game, the first player chooses one of his/her cards and puts it on the table (plays it). On the second turn, the second player chooses one of his/her cards such that the integer on it is greater than the integer on the card played on the first turn, and plays it. On the third turn, the first player chooses one of his/her cards such that the integer on it is greater than the integer on the card played on the second turn, and plays it, and so on — the players take turns, and each player has to choose one of his/her cards with greater integer than the card played by the other player on the last turn.

If some player cannot make a turn, he/she loses.

For example, if Alice has 44 cards with numbers [10,5,3,8][10, 5, 3, 8], and Bob has 33 cards with numbers [6,11,6][6, 11, 6], the game may go as follows:

  • Alice can choose any of her cards. She chooses the card with integer 55 and plays it.
  • Bob can choose any of his cards with number greater than 55. He chooses a card with integer 66 and plays it.
  • Alice can choose any of her cards with number greater than 66. She chooses the card with integer 1010 and plays it.
  • Bob can choose any of his cards with number greater than 1010. He chooses a card with integer 1111 and plays it.
  • Alice can choose any of her cards with number greater than 1111, but she has no such cards, so she loses.

Both Alice and Bob play optimally (if a player is able to win the game no matter how the other player plays, the former player will definitely win the game).

You have to answer two questions:

  • who wins if Alice is the first player?
  • who wins if Bob is the first player?

Alice 和 Bob 进行一场游戏。Alice 有 nn 张卡片,其中第 ii 张卡片上写有一个整数 aia_i;Bob 有 mm 张卡片,其中第 jj 张卡片上写有一个整数 bjb_j。

游戏的第一回合,先手玩家选择自己手中的一张卡片并将其置于桌面上(即出牌)。第二回合,后手玩家需从自己手中选择一张数字严格大于第一回合所出卡片数字的卡片并出牌。第三回合,先手玩家需从自己手中选择一张数字严格大于第二回合所出卡片数字的卡片并出牌,依此类推——双方轮流进行,且每位玩家在自己的回合中,必须选择一张数字严格大于对方上一回合所出卡片数字的己方卡片。

若某位玩家无法进行合法出牌,则该玩家判负。

例如,若 Alice 拥有 44 张卡片,数字为 [10,5,3,8][10, 5, 3, 8],而 Bob 拥有 33 张卡片,数字为 [6,11,6][6, 11, 6],则游戏可能如下进行:

  • Alice 可任选自己的一张卡片。她选择数字为 55 的卡片并出牌。
  • Bob 需选择一张数字大于 55 的卡片。他选择数字为 66 的卡片并出牌。
  • Alice 需选择一张数字大于 66 的卡片。她选择数字为 1010 的卡片并出牌。
  • Bob 需选择一张数字大于 1010 的卡片。他选择数字为 1111 的卡片并出牌。
  • Alice 需选择一张数字大于 1111 的卡片,但她没有这样的卡片,因此她输掉游戏。

Alice 和 Bob 均以最优策略进行游戏(即:若某玩家存在一种策略,使得无论对手如何应对都能获胜,则该玩家必定会采用该策略并获胜)。

你需要回答以下两个问题:

  • 若 Alice 为先手玩家,谁将获胜?
  • 若 Bob 为先手玩家,谁将获胜?

输入格式

The first line contains one integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. Each test case consists of four lines.

The first line of a test case contains one integer nn (1≤n≤501 \le n \le 50) — the number of cards Alice has.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤501 \le a_i \le 50) — the numbers written on the cards that Alice has.

The third line contains one integer mm (1≤m≤501 \le m \le 50) — the number of Bob's cards.

The fourth line contains mm integers b1,b2,…,bmb_1, b_2, \dots, b_m (1≤bi≤501 \le b_i \le 50) — the numbers on Bob's cards.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 测试用例的数量。每个测试用例由四行组成。

测试用例的第一行包含一个整数 nn(1≤n≤501 \le n \le 50)—— Alice 拥有的卡片数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤501 \le a_i \le 50)—— Alice 所有卡片上写的数字。

第三行包含一个整数 mm(1≤m≤501 \le m \le 50)—— Bob 的卡片数量。

第四行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \dots, b_m(1≤bi≤501 \le b_i \le 50)—— Bob 卡片上的数字。

输出格式

For each test case, print two lines. The first line should be Alice if Alice wins when she is the first player; otherwise, the first line should be Bob. The second line should contain the name of the winner if Bob is the first player, in the same format.

对于每个测试用例,输出两行。第一行:若 Alice 作为先手玩家时获胜,则输出 Alice;否则输出 Bob。第二行:若 Bob 作为先手玩家时获胜,则输出获胜者的名字,格式同上。

输入输出样例

  • 输入#1

    4
    1
    6
    2
    6 8
    4
    1 3 3 7
    2
    4 2
    1
    50
    2
    25 50
    10
    1 2 3 4 5 6 7 8 9 10
    2
    5 15

    输出#1

    Bob
    Bob
    Alice
    Alice
    Alice
    Bob
    Bob
    Bob

说明/提示

Let's consider the first test case of the example.

Alice has one card with integer 66, Bob has two cards with numbers [6,8][6, 8].

If Alice is the first player, she has to play the card with number 66. Bob then has to play the card with number 88. Alice has no cards left, so she loses.

If Bob is the first player, then no matter which of his cards he chooses on the first turn, Alice won't be able to play her card on the second turn, so she will lose.

我们来考虑示例中的第一个测试用例。

爱丽丝有一张写有整数 66 的卡片,鲍勃有两张卡片,数字分别为 [6,8][6, 8]。

如果爱丽丝先手,则她必须打出数字为 66 的卡片;随后鲍勃必须打出数字为 88 的卡片;此时爱丽丝已无剩余卡片,因此她输掉游戏。

如果鲍勃先手,则无论他在第一回合选择哪张卡片,爱丽丝在第二回合都无法打出她的卡片,因此她将输掉游戏。

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

首页