CF2183A.Binary Array Game

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alice and Bob are playing a game on an array aa of size nn, containing only numbers 0 and 1. Alice moves first, with each player alternating turns.

In a player's turn, he or she chooses two integers ll and rr such that 1≤l<r≤∣a∣1 \leq l \color{red}{ \lt } r \leq |a| (here, ∣a∣|a| denotes the current length of aa). Then, the subarray [al,al+1,…,ar][a_l,a_{l+1},\ldots,a_r] is replaced with a single number 1−min⁡(al,al+1,…,ar)1-\operatorname{min}(a_l,a_{l+1},\ldots,a_r). That is, if all numbers in the subarray are 11, then the subarray [al,al+1,…,ar][a_l,a_{l+1},\ldots,a_r] is removed, and the number 00 is inserted where the subarray was. Otherwise, the subarray [al,al+1,…,ar][a_l,a_{l+1},\ldots,a_r] is removed, and the number 11 is inserted where the subarray was.

The game ends when there is exactly one number left in the array (where the player to go cannot make legal moves). Alice wins if the final number is 00. Otherwise, Bob wins. Please determine who wins this game with optimal play.

爱丽丝和鲍勃正在一个长度为 nn 的数组 aa 上进行一场游戏,该数组仅包含数字 00 和 11。爱丽丝先手,双方轮流进行操作。

在一名玩家的回合中,他或她需选择两个整数 ll 和 rr,满足 1≤l<r≤∣a∣1 \leq l \color{red}{ \lt } r \leq |a|(此处 ∣a∣|a| 表示当前数组 aa 的长度)。然后,将子数组 [al,al+1,…,ar][a_l,a_{l+1},\ldots,a_r] 替换为单个数字 1−min⁡(al,al+1,…,ar)1-\operatorname{min}(a_l,a_{l+1},\ldots,a_r)。即:若该子数组中所有数字均为 11,则移除子数组 [al,al+1,…,ar][a_l,a_{l+1},\ldots,a_r],并在其原位置插入数字 00;否则,移除子数组 [al,al+1,…,ar][a_l,a_{l+1},\ldots,a_r],并在其原位置插入数字 11。

当数组中仅剩一个数字时,游戏结束(此时轮到行动的玩家无法进行合法操作)。若最终剩下的数字为 00,则爱丽丝获胜;否则鲍勃获胜。请判断在双方均采取最优策略的情况下,谁将获胜。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains a positive integer nn (3≤n≤1003 \le n \le 100), denoting the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (0≤ai≤10 \le a_i \le 1).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是各测试用例的描述。

每个测试用例的第一行包含一个正整数 nn(3≤n≤1003 \le n \le 100),表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(0≤ai≤10 \le a_i \le 1)。

输出格式

For each test case, output Alice if Alice wins, and Bob otherwise. You may output each character in any case. For example, the answers Alice, alice, ALICE, AliCe will all be interpreted the same.

对于每个测试用例,如果 Alice 获胜,则输出 Alice;否则输出 Bob。你可以以任意大小写形式输出每个字符。例如,答案 Alice、alice、ALICE、AliCe 均会被视为相同。

输入输出样例

  • 输入#1

    7
    3
    1 1 0
    3
    1 1 1
    3
    0 1 0
    4
    0 0 0 0
    5
    1 0 1 0 1
    6
    0 1 0 1 0 1
    6
    0 1 0 1 0 0

    输出#1

    Alice
    Alice
    Bob
    Bob
    Alice
    Alice
    Bob

说明/提示

In the first test case, Alice can win by choosing l=2l=2 and r=3r=3. Since 1−min⁡(a2,a3)=11-\operatorname{min}(a_2,a_3)=1, the subarray [1,0][1,0] is replaced with a single integer 11, and aa becomes [1,1][1,1]. At this point, it is Bob's turn, and the only move he has is to choose l=1l=1 and r=2r=2. Since 1−min⁡(a1,a2)=01-\operatorname{min}(a_1,a_2)=0, the array aa becomes [0][0]. The game now ends, and Alice wins because the last number is 00.

In the second test case, Alice can win by choosing l=1l=1 and r=3r=3 in her first move. The array becomes [0][0], and the game ends as a win for Alice immediately.

在第一个测试用例中,Alice 可以通过选择 l=2l=2 和 r=3r=3 获胜。由于 1−min⁡(a2,a3)=11-\operatorname{min}(a_2,a_3)=1,子数组 [1,0][1,0] 被替换为单个整数 11,此时数组 aa 变为 [1,1][1,1]。此时轮到 Bob 行动,他唯一可行的操作是选择 l=1l=1 和 r=2r=2。由于 1−min⁡(a1,a2)=01-\operatorname{min}(a_1,a_2)=0,数组 aa 变为 [0][0]。游戏结束,而 Alice 获胜,因为最后剩下的数是 00。

在第二个测试用例中,Alice 在第一步选择 l=1l=1 和 r=3r=3 即可获胜。数组变为 [0][0],游戏立即结束,Alice 获胜。

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

首页