LightOJ 1247 Matrix Game (尼姆博弈)
Description
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 containsn 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个数 每次选择一行取任意个数 谁取到最后一个谁赢。
题解:最基本常规的尼姆博弈 因为每一行可以任意取 所以每一行看成一堆即可
将每一行进行异或 所得结果ans如果不为0先手赢 否则后手赢
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int t,cas=;
cin>>t;
while(t--)
{
int m,n,data,ans=;
cin>>m>>n;
for(int i=;i<m;i++)
{
int sum=;
for(int j=;j<n;j++)
{
cin>>data;
sum+=data;
}
ans^=sum;
}
if(ans)
printf("Case %d: Alice\n",cas++);
else
printf("Case %d: Bob\n",cas++);
} return ;
}
LightOJ 1247 Matrix Game (尼姆博弈)的更多相关文章
- LightOJ - 1247 Matrix Game (Nim博弈)题解
题意: 给一个矩阵,每一次一个玩家可以从任意一行中选任意数量的格子并从中拿石头(但最后总数要大于等于1),问你谁赢 思路: 一开始以为只能一行拿一个... 将每一行石子数相加就转化为经典的Nim博弈 ...
- Light OJ 1393 Crazy Calendar (尼姆博弈)
C - Crazy Calendar Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Su ...
- hdu----(1849)Rabbit and Grass(简单的尼姆博弈)
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1849(Rabbit and Grass) 尼姆博弈
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Being a Good Boy in Spring Festival 尼姆博弈
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Descr ...
- HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)
Climbing the Hill Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Su ...
- Light OJ 1253 Misere Nim (尼姆博弈(2))
LightOJ1253 :Misere Nim 时间限制:1000MS 内存限制:32768KByte 64位IO格式:%lld & %llu 描述 Alice and Bob ar ...
- hdu-------(1848)Fibonacci again and again(sg函数版的尼姆博弈)
Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- BestCoder Round #65 hdu5591(尼姆博弈)
ZYB's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
随机推荐
- 克隆选择算法-python实现
CSAIndividual.py import numpy as np import ObjFunction class CSAIndividual: ''' individual of clone ...
- 【BZOJ-2434】阿狸的打字机 AC自动机 + Fail树 + DFS序 + 树状数组
2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 2022 Solved: 1158[Submit][Sta ...
- BZOJ-3212 Pku3468 A Simple Problem with Integers 裸线段树区间维护查询
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1278 Sol ...
- H2嵌入式数据库
一 H2 数据库 官网地址. http://www.h2database.com/html/cheatSheet.html
- 自动打包iOS项目
基于Lexrus的博文iOS-makefile,本文对自动打包涉及到的操作步骤以及理论基础进行了适当的补充. 请在阅读本文前先阅读<iOS makefile>.文章地址:http: ...
- Appserv环境下搭建的PHP环境升级PHP版本(支持微信端口以及thinkphp)
Appserv 2.5.10 升级PHP from version 5.2 to 5.3 最近,在使用Appserv 2.5.10 中的PHP开发微信时,遇到下面错误 Fatal error C ...
- B0BO TFS 安装指南(转载)
TFS2008安装过几次,每次都遇到点麻烦,结合网上的一些经验总结一下: Windows SharePoint Services 安装 Windows SharePoint Services你有两个选 ...
- You should blog even if you have no readers
Spencer Fry wrote a great post on "Why entrepreneurs should write." I would further add th ...
- ReactJS入门学习二
ReactJS入门学习二 阅读目录 React的背景和基本原理 理解React.render() 什么是JSX? 为什么要使用JSX? JSX的语法 如何在JSX中如何使用事件 如何在JSX中如何使用 ...
- kindle paperwhite折腾记
在亚马逊官网上买了一个kindle paperwhite 一代(849元) , 打算再买个皮套, 淘宝店 http://detail.tmall.com/item.htm?spm=a230r.1.1 ...