A - Matrix Game

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Submit Status

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 (尼姆博弈)的更多相关文章

  1. LightOJ - 1247 Matrix Game (Nim博弈)题解

    题意: 给一个矩阵,每一次一个玩家可以从任意一行中选任意数量的格子并从中拿石头(但最后总数要大于等于1),问你谁赢 思路: 一开始以为只能一行拿一个... 将每一行石子数相加就转化为经典的Nim博弈 ...

  2. Light OJ 1393 Crazy Calendar (尼姆博弈)

    C - Crazy Calendar Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Su ...

  3. hdu----(1849)Rabbit and Grass(简单的尼姆博弈)

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. hdu 1849(Rabbit and Grass) 尼姆博弈

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. Being a Good Boy in Spring Festival 尼姆博弈

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Descr ...

  6. HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)

    Climbing the Hill Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Su ...

  7. Light OJ 1253 Misere Nim (尼姆博弈(2))

    LightOJ1253 :Misere Nim 时间限制:1000MS    内存限制:32768KByte   64位IO格式:%lld & %llu 描述 Alice and Bob ar ...

  8. hdu-------(1848)Fibonacci again and again(sg函数版的尼姆博弈)

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  9. BestCoder Round #65 hdu5591(尼姆博弈)

    ZYB's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

随机推荐

  1. 【BZOJ-3293&1465&1045】分金币&糖果传递×2 中位数 + 乱搞

    3293: [Cqoi2011]分金币 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 854  Solved: 476[Submit][Status] ...

  2. TCP/IP详解 笔记八

    UDP协议 UDP是传输层协议,提供无连接不可靠的数据传输,其优点失效率高,确定确定是无序不可靠. 报文格式 UDP头部 TCP和UDP的端口号是独立的 UDP长度是指UDP数据报的总长度 UDP的校 ...

  3. soa vs cop

    soa强调分层:底层为高层提供服务: cop强调分块:有明确的职责和服务提供接口,为外部提供服务. SOA 原则非常强调将服务使用者和服务提供者分离开来,关于此类分离实际的含义,有很多不正式但非常有用 ...

  4. jquery------添加jQuery对象方法

    my.js $(document).ready(function(){ (function($){ $.fn.swapClass=function(class1,class2){ if(this.ha ...

  5. 初学Hibernate主键生成策略

    具有业务含义的主键叫自然主键:随机生成,不具备业务含义的字段作为主键,叫代理主键. 在表与POJO类关系映射文件XXX.hbm.xml中,可通过配置id元素下generator节点的class属性指定 ...

  6. Python socket编程之五:更新分时图

    f1.py # -*- coding: utf-8 -*- import socket import struct import sqlalchemy import pandas ########## ...

  7. 如何使用网盘托管git项目

    话说近年来git已经成为项目源代码管理的标准工具,有不少免费托管网站可供使用,详情参考这篇文章: http://www.cnblogs.com/zdz8207/archive/2012/05/20/2 ...

  8. LinkedList和ArrayList的区别/何时使用LinkedList和ArrayList

    1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构. 2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为LinkedList ...

  9. 反射中 GetCustomAttributes

    public abstract object[] GetCustomAttributes(bool inherit); 这是GetCustomAttributes方法的一个重载,参数为bool类型返回 ...

  10. 数据库的设计(E-R图,数据库模型图,三大范式)

    一.数据库设计的概念 数据库设计是将数据库中的数据实体及这些数据实体之间的关系,进行规划和结构化的过程. 二.数据库设计的重要性 如果一个数据库没有进行一个良好的设计,那么这个数据库完成之后他的缺点是 ...