C. Swap Game

C. Swap Game

Alice and Bob are playing a game on an array a of n positive integers. Alice and Bob make alternating moves with Alice going first.

In his/her turn, the player makes the following move:

  • If a1=0, the player loses the game, otherwise:
  • Player chooses some i with 2in. Then player decreases the value of a1 by 1 and swaps a1 with ai.

Determine the winner of the game if both players play optimally.

Input

The input consists of multiple test cases. The first line contains a single integer t (1t2104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (2n105) — the length of the array a.

The second line of each test case contains n integers a1,a2an (1ai109) — the elements of the array a.

It is guaranteed that sum of n over all test cases does not exceed 2105.

Output

For each test case, if Alice will win the game, output "Alice". Otherwise, output "Bob".

You can output each letter in any case. For example, "alIcE", "Alice", "alice" will all be considered identical.

Example

input

3
2
1 1
2
2 1
3
5 4 4

output

Bob
Alice
Alice

Note

In the first testcase, in her turn, Alice can only choose i=2, making the array equal [1,0]. Then Bob, in his turn, will also choose i=2 and make the array equal [0,0]. As a1=0, Alice loses.

In the second testcase, once again, players can only choose i=2. Then the array will change as follows: [2,1][1,1][1,0][0,0], and Bob loses.

In the third testcase, we can show that Alice has a winning strategy.

 

解题思路

  数组首个元素最先减到0的就会输,因此可以考虑一开始的a1>min1inaia1=min1inai这两种情况。

  如果是a1>min1inai,那么Alice可以每次把最小的元素换到第一个位置,然后轮到Bob时就会对这个最小的元素减1(这个元素还是最小元素)。而Bob只能将大于最小值(也就是大于a1)的元素换到第一个位置。可以发现,这样子Alice一定可以将最小元素减到0,使得Bob输掉比赛。

  如果是a1=min1inai,那么一开始Ailce对a1减去1后,a1就变成最小元素被换到数组的后面,这意味着下一次轮到Bob时,Bob是属于a1>min1inai这种情况的,意味着Bob会赢得比赛而Alice会输掉比赛。

  AC代码如下:

复制代码
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 const int N = 2e5 + 10;
 5 
 6 int a[N];
 7 
 8 void solve() {
 9     int n;
10     scanf("%d", &n);
11     for (int i = 0; i < n; i++) {
12         scanf("%d", a + i);
13     }
14     printf("%s\n", a[0] == *min_element(a, a + n) ? "Bob" : "Alice");
15 }
16 
17 int main() {
18     int t;
19     scanf("%d", &t);
20     while (t--) {
21         solve();
22     }
23     
24     return 0;
25 }
复制代码

 

参考资料

  Codeforces Round #832 (Div. 2) Editorial:https://codeforces.com/blog/entry/108782

posted @   onlyblues  阅读(49)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
Web Analytics
点击右上角即可分享
微信分享提示