Light OJ 1393 Crazy Calendar (尼姆博弈)

C - Crazy Calendar

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

Submit Status Practice LightOJ 1393

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 先手,每次向右或者下移动,谁不能移动谁输。
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    int i,j,n,m,t,x,cas=1;
    cin>>t;
    while(t--)
    {
        int ans=0;
        cin>>n>>m;
        int tmp=(n+m)%2;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                cin>>x;
                int a=(i+j)%2;
                if(a!=tmp)
                ans^=x;
            }
        }
        if(ans)
            printf("Case %d: win\n",cas++);
        else
            printf("Case %d: lose\n",cas++);

    }

    return 0;
}
时间: 2024-10-25 09:01:58

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

hdu 1907 尼姆博弈

John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 3745    Accepted Submission(s): 2116 Problem Description Little John is playing very funny game with his younger brother. There is one big bo

hdu 1850 Being a Good Boy in Spring Festival (尼姆博弈)

Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4658    Accepted Submission(s): 2781 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场悄悄给爸爸买

Being a Good Boy in Spring Festival(尼姆博弈)

Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 51 Accepted Submission(s): 45   Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场悄悄给爸爸买个小礼物主动地

最强头脑决定战中的尼姆博弈

最近看了一个日本综艺——最强头脑王决定战,顿觉以前看过的国内烧脑节目,类似“一站到底”之流与之相比真是相形见绌.“一站”说到底只是比谁题库背得熟,而日本这个真的是记忆.计算.观察.推理等各种能力的综合考察,比赛选手们各显神通,观众如我看得也是如痴如醉. 其中比赛到第二轮时有一道题如下:有四堆不同色的棋子,每堆分别有3.5.6.7枚,由选手和电脑开始依次从其中取出一些棋子,每次只可取同一堆的任意枚,如此交替直至取完所有棋子,谁取到最后一枚棋子谁输. 当时水上小哥不假思索地取子很轻松就赢了,让评委们

nyoj 取石子(三)(尼姆博弈的定理运用)

取石子(三) 时间限制:1000 ms |  内存限制:1000 KB 难度:6 描述 小王喜欢与同事玩一些小游戏,今天他们选择了玩取石子. 游戏规则如下:共有N堆石子,已知每堆中石子的数量,两个人轮流取子,每次只能选择N堆石子中的一堆,取一定数量的石子(最少取一个),取过子之后,还可以将该堆石子中剩下的任意多个石子中随意选取几个放到其它的任意一堆或几堆上.等哪个人无法取子时就表示此人输掉了游戏.注意,一堆石子没有子之后,就不能再往此处放石子了. 假设每次都是小王先取石子,并且游戏双方都绝对聪明

hdu 1849(Rabbit and Grass) 尼姆博弈

Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3864    Accepted Submission(s): 2919 Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去逛

HDU 4315 Climbing the Hill (尼姆博弈)

Climbing the Hill Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description Alice and Bob are playing a game called "Climbing the Hill". The game board consists of cells arranged vertically, as the

HDU5014 Game(尼姆博弈)

Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 493    Accepted Submission(s): 380 Problem Description Here is a game for two players. The rule of the game is described below: ● In the beg

HDU 2176 取(m堆)石子游戏 尼姆博弈

题目思路: 对于尼姆博弈我们知道:op=a[1]^a[2]--a[n],若op==0先手必败 一个简单的数学公式:若op=a^b 那么:op^b=a: 对于第i堆a[i],op^a[i]的值代表其余各个堆值的亦或值. 我们现在希望将a[i]改变成某个更小的值使得,op^a[i]=0,反过来a[i]=op^0,输出它就好了 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h&