lightoj1393——阶梯博弈

题目链接:http://lightoj.com/volume_showproblem.php?problem=1393

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

Note

Dataset is huge, use faster I/O methods.

 

题目翻译:

‎学习就够了。现在回到问题,给定一个网格,在每个单元格有一些硬币。Inky和Pinky正在玩一个游戏,从上述问题中获得灵感。在每个回合中,玩家选择一个非空单元格,然后从该单元格中删除一个或多个硬币,并将它们完全放在单元格的右侧或正好位于其下方。玩家不能把硬币分开,把一部分放在右边,把另一部分放下。请注意,对于右列中的单元格,播放器无法将其移动到更右侧,底部行也是如此。因此,玩家不能从右下角移动硬币。当没有移动可用时,游戏将结束,最后移动的玩家将获胜。现在很谦虚,要求平基先搬走。你能说如果平基都打得完美,你能否说?‎

‎输入

输入以整数‎‎T‎‎(=‎‎100)‎‎开头,表示测试用例的数量。

每个案例以包含两个整数 R ‎‎C(1 = R = C = 50000)‎‎的行开头,其中‎‎R‎‎表示行数,C 分别表示网格的列数。 ‎‎接下来的每一条‎‎R‎‎行都包含表示网格的‎‎C‎‎空间分隔的整数。这些整数位于‎‎范围 [0, 10‎‎9‎‎]‎‎中。

输出

对于每个测试用例,输出案例编号后‎‎跟"赢",‎‎如果Pinky可以赢‎‎或"输"。

‎‎

‎‎阶梯博弈裸题,就相当于奇数号台阶的尼姆博弈。

#include<iostream>
using namespace std;
int main(){
	int T,n,m;
	scanf("%d",&T);
	for(int kcase=1;kcase<=T;kcase++){
		scanf("%d%d",&n,&m);
		long long ans=0;
		for(int i=1;i<=n;++i){
			for(int j=1;j<=m;++j){
				int x;
				scanf("%d",&x);
				if(((n+m)-(i+j))%2)
					ans^=x;
			}
		}
		if(ans) printf("Case %d: win\n",kcase);
		else printf("Case %d: lose\n",kcase);
	}
	return 0;
}

‎‎

‎‎

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值