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
/*
* @Author: lyuc
* @Date: 2017-04-25 20:23:56
* @Last Modified by: lyuc
* @Last Modified time: 2017-04-25 20:41:17
*/
/*题意:给你一个n*m的矩阵,每个格子里都有一定数量的石头,两个人轮流移动石头,每次选择一个格子,移动至少一个石头,
* 但是只能移动到右边一个,或者下边一个格子,谁不能移动了就输了。
*
*初步思路:如果这个格子到右下角的步数是偶数的话,那么就不用考虑这个格子了,因为如果是偶数,那么先手移动几个,后手
 * 就移动几个,这样就抵消了。所以只需要考虑奇数步数的格子,这就是一个简单的NIM博弈了
*//
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int t;
int n,m;
int num;
LL res;
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&t);
for(int ca=;ca<=t;ca++){
printf("Case %d: ",ca);
res=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&num);
if(((n+m)-(i+j))%)
res^=num;
}
}
printf(res?"win\n":"lose\n");
}
return ;
}
 

Crazy Calendar (阶梯博弈变形)的更多相关文章

  1. HDU 4315 阶梯博弈变形

    n个棋子,其中第k个是红色的,每个棋子只能往上爬,而且不能越过.重叠其他棋子,谁将红色棋子移到顶部谁赢. 由于只能往上爬,所以很像阶梯博弈.这题有2个限制,棋子不能重叠,有红棋存在 首先不考虑红色棋, ...

  2. HDU 3389 阶梯博弈变形

    n堆石子,每次选取两堆a!=b,(a+b)%2=1 && a!=b && 3|a+b,不能操作者输 选石子堆为奇数的等价于选取步数为奇数的,观察发现 1 3 4 是无法 ...

  3. LightOJ 1393 Crazy Calendar(博弈)题解

    题意:r*c方格中,每个格子有一定石子,每次移动每格任意数量石子,只能向下或者向右动一格,不能移动为败 思路:显然是Nim,到右下曼哈顿距离为偶数的不用管,因为先手动一下后手动一下最后移到右下后还是先 ...

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

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

  5. hdu4318阶梯博弈nim变形

    阶梯博弈原理参考:http://www.cnblogs.com/jiangjing/p/3849284.html 这题计算每两个之间的间隔就行了,如果是奇数个就把第一个前面的看作一个,偶数个就是两个点 ...

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

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

  7. POJ1704 Georgia and Bob (阶梯博弈)

    Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Subm ...

  8. HDU 4315:Climbing the Hill(阶梯博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:有n个人要往坐标为0的地方移动,他们分别有一个位置a[i],其中最靠近0的第k个人是king,移动的 ...

  9. hdu 3389 Game (阶梯博弈)

    #include<stdio.h> int main() { int t,n,ans; int i,j,x; scanf("%d",&t); ;j<=t; ...

随机推荐

  1. ArrayList 和 LinkedList 的实现与区别

    (转载请标明出处) 1.ArrayLis t的实现 2.LinkedLis t的实现 3.ArrayList 和 LinkedList 的区别 ArrayList 的实现: 1.MyArrayList ...

  2. [js高手之路] html5 canvas系列教程 - 状态详解(save与restore)

    本文内容与路径([js高手之路] html5 canvas系列教程 - 开始路径beginPath与关闭路径closePath详解)是canvas中比较重要的概念.掌握理解他们是做出复杂canvas动 ...

  3. mybatis 错误CGLIB is not available

    ### Error querying database. Cause: java.lang.IllegalStateException: Cannot enable lazy loading beca ...

  4. matplotlib学习之绘图基础

    matplotlib:http://www.cnblogs.com/jasonhaven/p/7609059.html 1.基本图形 散点图:显示两组数据的值,每个点的坐标位置由变量的值决定,头一组不 ...

  5. Perfect Pth Powers poj1730

    Perfect Pth Powers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16383   Accepted: 37 ...

  6. S2_SQL_第五章

    UNIQUE|FULLTEXT|SPATIAL:分别表示唯一索引,全文索引和空间索引,为可选参数index_name;指定索引名称table_name;指定创建索引表名colymn_name;指定需要 ...

  7. 自测-4 Have Fun with Numbers

    Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...

  8. 如何用java语言获取某个网页的源代码

    import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; public class W ...

  9. 苹果iPhone X上搭载的那颗A11仿生芯片,到底牛在哪?

    苹果iPhone X上搭载的那颗A11仿生芯片,到底牛在哪? 上周,苹果公司在刚刚落成投入使用的“飞船”新总部(Apple Park)举行2017年秋季新品发布会,整场发布会基本被iPhone X抢尽 ...

  10. 定制Three.js中Material属性

    1.找到想要更改的着色器代码