题目:
Given an m x n matrix, where m denotes the number of rows and n denotes the number of columns and in each cell a pile of stones is given. For example, let there be a 2 x 3 matrix, and the piles are
2 3 8
5 2 7
That means that in cell(1, 1) there is a pile with 2 stones, in cell(1, 2) there is a pile with 3 stones and so on.
Now Alice and Bob are playing a strange game in this matrix. Alice starts first and they alternate turns. In each turn a player selects a row, and can draw any number of stones from any number of cells in that row. But he/she must draw at least one stone. For example, if Alice chooses the 2nd row in the given matrix, she can pick 2 stones from cell(2, 1), 0 stones from cell (2, 2), 7 stones from cell(2, 3). Or she can pick 5 stones from cell(2, 1), 1 stone from cell(2, 2), 4 stones from cell(2, 3). There are many other ways but she must pick at least one stone from all piles. The player who can't take any stones loses.
Now if both play optimally who will win?
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing two integers: m and n (1 ≤ m, n ≤ 50). Each of the next m lines contains n space separated integers that form the matrix. All the integers will be between 0 and 109 (inclusive).
Output
For each case, print the case number and 'Alice' if Alice wins, or 'Bob' otherwise.
Sample Input
2
2 3
2 3 8
5 2 7
2 3
1 2 3
3 2 1
Sample Output
Case 1: Alice
Case 2: Bob
解题报告:
两个人要玩游戏,然后有m行n列的石子堆,然后两人依次轮流去取一行石子中的至少一个石子,刚开始没有看懂这句英文,后来看了一下样例,才理解。其实本质仍然是nim博弈,每行石子之和异或起来就可以了
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
int T;
scanf("%d",&T);
int kase=0;
while(T--)
{
int n,m;
scanf("%d%d",&m,&n);
int ans=0;
while(m--)
{
int sum=0;
int a;
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
sum+=a;
}
ans^=sum;
}
printf("Case %d: ",++kase);
if(ans==0)
{
printf("Bob\n");
}
else
{
printf("Alice\n");
}
}
}