题解:P15320 【MX-X24-T1】「RiOI-7」Ah, It's Yesterday Once More
P15320题解
题目传送门
题目大意
给定
若剩余元素为
思路
可将除
分类讨论:
-
当
n==1 时:若序列为:0 则Alice赢,否则Bob赢。 -
当
n==2 时:若序列中全为1 ,Alice只能合成1,1 为0 Alice必赢。反之Bob必赢。若序列为0,1 合成为1 Bob必赢。 -
当
n>=3 时:Alice若要赢则需让序列变为1,1 而Bob要赢则需让序列变为1,0 或0,0 。已知当所选子集中有至少一个
0 时mex=1 ,所以当序列中有至少一个1 时Alice就可以将除了一个1 以外剩余的0 与1 全一次性变成1 构成1,1 。特别的,当序列中全是1 时,Alice可一次性将所有的1 变成一个0 赢下比赛像这样:
{1,1,1,1,1,1,1,0,0}->{1}+{1,1,1,1,1,1,0,0}->{1,1}。
{1,1,1,1,1}->{0}。
否则Bob赢。
AC code
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[2];
signed main(){
//freopen("","r",stdin);
//freopen("","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
a[0]=0;
a[1]=0;
int n;
cin>>n;
for(int i=1;i<=n;i++){
int x;
cin>>x;
if(x==0){
a[0]++;
}else{
a[1]++;
}
}
if(n==1){
if(a[0]){
cout<<"Alice"<<endl;
}else{
cout<<"Bob"<<endl;
}
}else if(n==2){
if(a[0]&&a[1]){
cout<<"Bob"<<endl;
}else if(a[0]){
cout<<"Bob"<<endl;
}else if(a[1]){
cout<<"Alice"<<endl;
}
}else{
if(a[1]>=1){
cout<<"Alice"<<endl;
}else{
cout<<"Bob"<<endl;
}
}
}
return 0;
}