CF2181F.Fragmented Nim
普及/提高-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The classical game of Nim goes as follows. There are n piles of stones, and pile i initially consists of ai stones. Alice and Bob take turns; Alice goes first. On their turn, a player chooses any non-empty pile and removes any positive number of stones from it. The player who takes the last stone wins.
After playing a lot of Nim, Alice and Bob decided to vary the rules a little bit. In this variation, the player whose turn it is does not choose a pile — their opponent does it for them! However, the player still gets to decide the number of stones to remove from that pile.
Alice still moves first. On Alice's turn Bob chooses any non-empty pile, and then Alice removes any positive number of stones from it. Similarly, on Bob's turn Alice chooses any non-empty pile, and then Bob removes any positive number of stones from it.
For the given configuration of stones in the piles, determine who will win if both players follow the optimal strategy.
经典的 Nim 游戏规则如下:共有 n 堆石子,其中第 i 堆初始时包含 ai 颗石子。Alice 和 Bob 轮流进行操作,Alice 先手。在自己的回合中,玩家任选一个非空石子堆,并从中移除任意正整数颗石子。取走最后一颗石子的玩家获胜。
在玩了大量 Nim 游戏后,Alice 和 Bob 决定对规则稍作修改。在此变种规则中,当前轮到行动的玩家不选择石子堆——该选择由其对手代为完成!但该玩家仍可自主决定从所选石子堆中移除多少颗石子(必须为正整数)。
Alice 依然先手。在 Alice 的回合中,Bob 任选一个非空石子堆,然后 Alice 从中移除任意正整数颗石子;类似地,在 Bob 的回合中,Alice 任选一个非空石子堆,然后 Bob 从中移除任意正整数颗石子。
对于给定的石子堆配置,请判断:若双方均采用最优策略,谁将获胜?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n, denoting the number of piles (1≤n≤2⋅105).
The second line contains n integers a1,a2,…,an, denoting the number of stones in the piles (1≤ai≤109).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n,表示石堆的数量(1≤n≤2⋅105)。
第二行包含 n 个整数 a1,a2,…,an,表示各石堆中的石子数量(1≤ai≤109)。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, print the name of the winner of the game if both players follow the optimal strategy: "Alice" or "Bob".
对于每个测试用例,若双方玩家均采用最优策略,则输出游戏获胜者的名字:“Alice”或“Bob”。
输入输出样例
输入#1
3 3 1 2 3 1 1 5 10 3 4 7 4
输出#1
Bob Alice Alice
说明/提示
In the first test case, here's one possible way the game could proceed:
- Bob chooses the first pile. Alice removes 1 stone from it.
- Alice chooses the third pile. Bob removes 2 stones from it.
- Bob chooses the third pile. Alice removes 1 stone from it.
- Alice chooses the second pile. Bob removes 2 stones from it and wins.
In the second test case, Bob chooses the only pile, and Alice wins by removing the only stone from it.
在第一个测试用例中,游戏可能按如下方式进行:
- Bob 选择第一堆石子。Alice 从中移除 1 颗石子。
- Alice 选择第三堆石子。Bob 从中移除 2 颗石子。
- Bob 选择第三堆石子。Alice 从中移除 1 颗石子。
- Alice 选择第二堆石子。Bob 从中移除 2 颗石子并获胜。
在第二个测试用例中,Bob 选择唯一的一堆石子,Alice 通过从中移除唯一的一颗石子而获胜。
输入解题思路,AI测评打分。不知道怎么写?