Matrix Game(尼姆博弈变形)

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

题意:给你一个nXm的矩阵,没个人每次能在同一行选任意堆取任意数量的石子(至少为1)谁先取完谁赢

思路:把每一行看成一堆,异或和一发

/*
 *           ┏┓       ┏┓
 *          ┏┛┗━━━━━┛┗
 *          ┃         ┃  
 *          ┃   ━     ┃
 *          ┃ >   <   ┃
 *          ┃         ┃
 *          ┃... ⌒ ...   ┃
 *          ┃                ┃
 *          ┗━┓          ┏┛
 *            ┃          ┃ Code is far away from bug with the animal protecting          
 *            ┃          ┃   神兽保佑,代码无bug
 *            ┃          ┃           
 *            ┃          ┃        
 *            ┃          ┃
 *            ┃          ┃           
 *            ┃          ┗━━━┓
 *            ┃                  ┣┓
 *            ┃                  ┏┛
 *            ┗┓┓┏━━━━┓┏┛
 *             ┃┫┫       ┃┫┫
 *             ┗┻┛       ┗┻┛
 */

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include<algorithm>

#define EPS 0.00000000001
using namespace std;
typedef long long ll;
const int  mod = 1e9 + 7;
const int N = 5e5 + 5;
ll dp[N];
ll E[N];

int main()
{
	ios_base::sync_with_stdio(false);
	
	
	int T;
	cin >> T;
	for (int t = 1; t <= T; t++)
	{
		int n, m;
		cin >> n >> m;
		int x, sum = 0,ans=0;
		for (int i = 0; i < n; i++)
		{
			sum = 0;
			for (int j = 0; j < m; j++)
			{
				cin >> x;
				sum += x;
			}
			ans ^= sum;
		}
		if (ans)
			printf("Case %d: Alice\n", t);
		else
			printf("Case %d: Bob\n", t);
	}
	
	return 0;


}```

上一篇:9.利用服务器公钥直接登录服务器


下一篇:#背包#洛谷 4026 [SHOI2008]循环的债务