Crazy Calendar Light OJ 1393 (Nim博弈)
来源:互联网 发布:房地产市场调研 知乎 编辑:程序博客网 时间:2024/05/20 08:00
Crazy Calendar Light OJ 1393 (Nim博弈) :http://acm.hust.edu.cn/vjudge/contest/view.action?cid=112620#problem/C 传送门:nefu
题面描述:
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
题目大意:
再一个c行r列的格子中每个格点处都放置若干个石子,两人开始游戏,分别合法的操作是向下移动石子和向右移动石子,Pinky先手,谁最后一次操作谁赢。
题目分析:
当把石子全部移动到右下角时,结束移动,所以与右下奇偶性一致的格点位置,都不能直接到达,则先手必败;则只需考虑与右奇偶性不一样的位置,则可以看成Nim博弈,最后Nim博弈不为0时胜,否则,败。
代码实现:
#include <iostream>using namespace std;int main(){ int t,r,c,a,casenum=0; int ans; cin>>t; while(t--) { cin>>r>>c; ans=0; int odd=(r+c)&1; for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { cin>>a; if(((i+j)&1)!=odd) ans^=a; } } if(ans==0) cout<<"Case "<<++casenum<<": lose"<<endl; else cout<<"Case "<<++casenum<<": win"<<endl; } return 0;}
- Crazy Calendar Light OJ 1393 (Nim博弈)
- Light OJ 1393 - Crazy Calendar(博弈)
- Light OJ 1393 Crazy Calendar (尼姆博弈)
- nim博弈_______Crazy Calendar( lightoj 1393 )
- Light OJ 1253 Misere Nim (尼姆博弈(2))
- Light OJ 1253 Misere Nim
- Acdream 1416 Crazy Nim(简单博弈找规律)
- light oj 1031 区间dp+博弈
- light oj 1031(区间dp+博弈)
- light oj 1020 - A Childhood Game (博弈)
- nim 博弈
- Nim博弈
- Nim博弈
- NIM 博弈
- Nim 博弈
- Nim博弈
- nim 博弈
- Nim博弈
- Hadoop安装配置、运行第一个WordCount示例程序
- Android Studio目录结构及工程项目结构解析
- Android 嵌套滑动机制(NestedScrolling)
- Xcode7 中创建静态库:.a 和 .framework(二)
- 遗传网络算法
- Crazy Calendar Light OJ 1393 (Nim博弈)
- 设计模式与实例代码:Proxy模式
- 正则表达式
- 学习mycat过程回顾
- 06-图2 Saving James Bond - Easy Version (25分)
- Java基本语法和命名规范
- QT + vs 运行的项目出现控制台的解决办法
- windows下安装SVN服务器端和客户端和MyEclipse支持
- XCODE7以后不能使用HTTP协议解决办法