Yet Another Game of Stones ZOJ - 3964
情况
- 如果B[i]==2 ,但A[i] %2 ==1 ,对于Alice来说肯定没法取完,所以必输
- 考虑B[i] == 1,B[i] == 2,这两种情况,如果B[i]==1,A[i] == 1,这就相当于nim博弈了,如果B[i]==1&A[i] >1的个数加上B[i] ==2 &&B[i] > 1的个数大于等于2,那么这种情况无论nim_sum ==0 ,或者不等于零,都是必输的
- 如果B[i] == 1&&A[i] > 1的个数为1,那么肯定要先取这个,考虑取奇数个之后的nim值
- 如果B[i] == 2&&A[i] > 1的个数为1,那么肯定要取完,考虑剩下来的nim值
- 其他情况退化成nim博弈
const int maxn = 1e6+100;
int A[maxn];
int B[maxn];
int n,T;
bool solve(){
scanf("%d",&n);
int sum = 0;
int c1 = 0,c2 =0;
rep(i,0,n) scanf("%d",&A[i]),sum ^= A[i];
rep(i,0,n) {
scanf("%d",&B[i]);
}
rep(i,0,n){
if(B[i] ==2 && A[i] %2 ==1) return 0;
if(B[i] == 1&&A[i] > 1) c1++;
if(B[i] == 2&&A[i] > 1) c2++;
}
if(c1 +c2 > 1) return 0;
if(c1 == 1){
// for(auto c:)
rep(i,0,n)
{
if(A[i] > 1&&B[i] == 1){
sum ^= A[i];
sum ^= (A[i]%2==0);
return !sum;
}
}
}
if(c2 == 1){
rep(i,0,n){
if(A[i] > 1&&B[i] == 2){
sum ^= A[i];
return !sum;
}
}
}
return sum;
}
int main(void)
{
cin>>T;
while(T--){
printf("%s\n", solve() ? "Alice" : "Bob");
}
return 0;
}