(博弈论)Even Number Addicts

C. Even Number Addicts
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Alice and Bob are playing a game on a sequence a1,a2,,an1,2,…, of length n. They move in turns and Alice moves first.

In the turn of each player, he or she should select an integer and remove it from the sequence. The game ends when there is no integer left in the sequence.

Alice wins if the sum of her selected integers is even; otherwise, Bob wins.

Your task is to determine who will win the game, if both players play optimally.

Input

Each test contains multiple test cases. The first line contains an integer t (1t1001≤≤100) — the number of test cases. The following lines contain the description of each test case.

The first line of each test case contains an integer n (1n1001≤≤100), indicating the length of the sequence.

The second line of each test case contains n integers a1,a2,,an1,2,…, (109ai109−109≤≤109), indicating the elements of the sequence.

Output

For each test case, output "Alice" (without quotes) if Alice wins and "Bob" (without quotes) otherwise.

Example
input Copy
4
3
1 3 5
4
1 3 5 7
4
1 2 3 4
4
10 20 30 40
output Copy
Alice Alice Bob Alice
Note

In the first and second test cases, Alice always selects two odd numbers, so the sum of her selected numbers is always even. Therefore, Alice always wins.

In the third test case, Bob has a winning strategy that he always selects a number with the same parity as Alice selects in her last turn. Therefore, Bob always wins.

In the fourth test case, Alice always selects two even numbers, so the sum of her selected numbers is always even. Therefore, Alice always wins.

 

解析:

共识:奇数 + 奇数 = 偶数;奇数 + 偶数 = 奇数;偶数 + 偶数 = 偶数。

统计序列 a 中偶数 ai 和奇数 ai 分别出现的次数 e、o,依次可确定下列几种情况,决定二人胜负态:

  1. 当 ≡2(mod4)o2(mod4) 时, Bob 存在必胜态;

Bob 仅需保证每次所取数字与 Alice 所取数字奇偶性相同即可,这样可以使二者取走的奇数个数相同。若在此过程中 Alice 取走了最后一个偶数,奇数必然剩余偶个。随后,Alice 和 Bob 各自将选择剩余奇数的一半。最后,Alice 和 Bob 都拥有 22o 个奇数,Alice 和为奇数,Alice 败。

  1. 当 ≡3(mod4)o3(mod4) 时, Alice 存在必胜态;

Alice 首先选择一个奇数,若 Bob 能从剩下的数字中取走偶个奇数,则 Bob 胜。从情况 1 中可知,Bob 必败。

  1. 当 ≡0(mod4)o0(mod4) 时, Alice 存在必胜态;

Alice 首先选择一个偶数,在随后的操作中,Alice 仅需保证每次所取数字与 Bob 所取数字奇偶性相同即可,这样可以使二者取走的奇数个数相同。若在此过程中偶数被取完,奇数必然剩余偶个。随后,Alice 和 Bob 各自将选择剩余奇数的一半。最后,Alice 和 Bob 都拥有 22o 个奇数,Alice 和为偶数,Alice 胜。

  1. 当 ≡1(mod4)o1(mod4) 时,先选择奇数的人败。

先选择奇数的人将会导致对手出现情况 3,对手必胜。博弈开始时,如果 e 为偶即 ≡0(mod2)e0(mod2),则 Bob 将会取走最后一个偶数,Alice 败;e 为奇即 ≡1(mod2)e1(mod2),则 Alice 胜。

复制代码
//https://www.luogu.com.cn/problem/CF1738C #include<bits/stdc++.h> using namespace std; const int N=1e5+10; int num1,num2,n,res,t; int main() { cin>>t; while(t--) { cin>>n; for(int i=1;i<=n;i++) { int a; cin>>a; if(a%2==0) num2++; else num1++; } if(num1%4==0||num1%4==3||(num1%4==1&&num2%2==1)) cout<<"Alice"<<endl; else cout<<"Bob"<<endl; } return 0; }
复制代码

 


__EOF__

本文作者Sakurajimamai
本文链接https://www.cnblogs.com/o-Sakurajimamai-o/p/17480899.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   o-Sakurajimamai-o  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
-- --
点击右上角即可分享
微信分享提示