题意:给出m行n列的矩阵,每个点有石子,alice和bob玩游戏,他们从每一行里拿任意个石子但不能不拿,alice先拿,最后谁不能那谁输。问最后谁能赢。
题目分析:把每行值加起来就是一个NIM博弈,很水的。直接异或求值。
对于NIM博弈请看博客:http://blog.csdn.net/bigbigship/article/details/44652361;
代码如下:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
int k=1;
while(t--){
int n,m;
int x;
scanf("%d%d",&n,&m);
int ans=0;
for(int i=0;i<n;i++){
int sum=0;
for(int j=0;j<m;j++){
scanf("%d",&x);
sum+=x;
}
ans^=sum;
}
if(ans==0)printf("Case %d: Bob\n",k++);
else printf("Case %d: Alice\n",k++);
}
return 0;
}