C - Crazy Calendar

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

Description

2011 was a crazy year. Many people all over the world proposed on 11-11-11, married on 11-11-11, some even went through surgery only to have 11-11-11 as their child's birth date. How crazy people can be! Don't they see there is a "20" hidden? Then what to do? A very elegant solution came from ARR, a very famous and funny character - why do we need to follow Christian (or some calls it Gregorian) calendar? Why don't we start our own calendar on the day of marriage? And those who like to celebrate their marriage ceremony too frequent, why don't they declare only 1 day per year. In that fashion they can celebrate their anniversary every day. And may be one minute a year or a second or ... Uh.. getting complex. Let's back to the title. From now, we start to have a new calendar system, "Kisu Pari Na". And we hope to update this calendar on every national contest.

The purpose of this calendar is - we all will try our best to learn something new in every year. For this first year let's learn some combinatory. It reminds me of my first year in college. I faced this problem but could not solve this then. But see how easy it is:

Say you start from upper left cell and want to go to lower right cell. The only restriction is you can only move downward or rightward. How many ways are there? How to solve it? Not that difficult. You have to go two times Down and three times Right (whichever way you try) to reach the goal from the starting cell, right? So the answer is number of ways you can arrange two D (represents Down) and three R (represent Right). 2 same characters and 3 same characters, total 5 characters. So it is:

Or =D+RCR. Easy isn't it?

Ok enough with learning. Now back to problem, given a grid and at each cell there are some coins. Inky and Pinky are playing a game getting inspiration from the above problem. At each turn, a player chooses a non empty cell and then removes one or more coins from that cell and put them to the cell exactly right of it or exactly beneath it. A player can't divide the coins and put one part to right and others to down. Note that, for the cells at the right column the player can't move it to more right, and same for the bottom-most row. So a player can't move coins from the lower right cell. The game will finish when no moves are available and the player who moved last will win. Now inky being very modest asked Pinky to move first. Can you say if Pinky will win if both play perfectly?

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing two integers R C (1 ≤ R * C ≤ 50000), where R denotes the number of rows and C denotes the number of columns of the grid respectively. Each of the next R lines contains C space separated integers denoting the grid. These integers lie in the range [0, 109].

Output

For every test case, output case number followed by "win" if Pinky can win or "lose".

Sample Input

1

2 2

1 1

1 1

Sample Output

Case 1: lose

题意:给定n*m的一个方格,每个方格含x个石子,Pinky 先手,每次可以取任意数目石子向右或者下移动,谁不能移动谁输。

题解:如果该方格中的一个点的坐标与n+m的奇偶性相同,则不需要考虑该点。因为若该点与n+m奇偶性相同,设该点坐标为(i,j)(0<=i<=n,0<=j<=m)则(n+m)-(i+j),即到达终点的步数为偶数,也就是说先手怎么移动后手就怎么移动,先手右后手就下,先手下后手就右,也就是说等于没移动。所以我们只需要考虑与n+m不同的,也就是n+m和i+j一个奇数一个偶数,也就是说,这些点距离终点只需要也只能移动一次,每次可以从一个方格中取任意个石子移动,这就转化为了尼姆博弈中的取石子问题,因为尼姆博弈中可以随意取石子。异或为0为必败态一定会转化为必胜态,异或为1为必胜态可以转化为必败态,具体详见下最基础的尼姆博弈--取石子问题,就ok了。

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int t,cas=;
cin>>t;
while(t--)
{
int r,c,data,ans=;
cin>>r>>c;
for(int i=; i<r; i++)
{
for(int j=; j<c; j++)
{
cin>>data;
int a=((r+c)-(i+j))%;
if(a)
ans^=data;
}
}
if(ans)
printf("Case %d: win\n",cas++);
else
printf("Case %d: lose\n",cas++);
}
return ;
}

Light OJ 1393 Crazy Calendar (尼姆博弈)的更多相关文章

  1. light oj 1393 - Crazy Calendar 博弈论

    思路:当移到右下角时,就不能移动了.所以与右下角的奇偶性相同的位置,都不能直接到达,先手必败! 只需考虑与右下角奇偶不同的位置,可以看成NIM博弈.最后NIM和不为0的胜,否者败!! 代码如下: #i ...

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

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

  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. LightOJ 1247 Matrix Game (尼姆博弈)

    A - Matrix Game Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submi ...

  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. asp.net 回发或回调参数无效的各种情况分析及解决办法

    昨天,在实现级联菜单的时候,突然出现一下错误: 回发或回调参数无效.在配置中使用 <pages enableEventValidation="true"/> 或在页面中 ...

  2. hihocoder 1169 猜数字

    传送门 时间限制:10000ms 单点时限:5000ms 内存限制:256MB 描述 你正在和小冰玩一个猜数字的游戏.小冰首先生成一个长为N的整数序列A1, A2, …, AN.在每一轮游戏中,小冰会 ...

  3. linux学习笔记二-----文件权限管理

    一.分析文件权限(ln -s 文件名 快捷方式名 用来创建文件的快捷方式,下方ll查看信息时会在第一个字符处显示l) [hjp@bogon ~]$ ll total 4 drwxrwxr-x. 2 h ...

  4. tomcat Host及Context 配置

    参考资料: 一.Host配置 对一个Tomcat,可以配置多台虚拟主机.简单地说,就是让一台服务器可以对应多个主机名.这在Tomcat中称之为Host.要求每个Host的Name必须唯一. 配置方法: ...

  5. Python socket编程之六:多窗口的应用

    import struct import sqlalchemy import pandas import matplotlib.pyplot as Plot from matplotlib.finan ...

  6. SQL中CONVERT转化函数的用法

    格式:CONVERT(data_type,expression[,style])说明:此样式一般在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,c ...

  7. Java设计原则:面向接口的设计

    前言:在一个面向对象的系统中,系统的各种功能是由许许多多的不同对象协作完成的.在这种情况下,各个对象内部是如何实现对系统设计人员来说就不那么重要:而各个对象之间的协作关系则成为系统设计的关键.小到不同 ...

  8. ZLIB 库

    zlib 编辑 zlib是提供数据压缩用的函式库,由Jean-loup Gailly与Mark Adler所开发,初版0.9版在1995年5月1日发表.zlib使用DEFLATE算法,最初是为libp ...

  9. IE7 -- 鼠标移入显示下拉框 不显示的问题 / 以及宽度问题

    这个问题,真的是打击到我了,我一度不相信自己无法解决这个问题.但是我就是真的没有解决. 那么问题解决方案是: 第一 祖先级别有一个相对定位,父级再有一个定位,那么绝对定位显示出来的元素就会不显示. 第 ...

  10. angularjs中关于当前路由再次点击强制刷新

    angularjs中,有一个机制,就是当前路由再次点击的时候,不会再刷新页面,这实在是愁坏了包子,因为业务人员要求一定要刷新,于是我各种百度,然并卵....呜呜呜~~~~~ 于是乎,我就想到写指令了, ...