POJ_P2311 Cutting Game(博弈+SG函数)
2016-03-08 19:25
471 查看
POJ传送门
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3547 Accepted: 1320
Description
Urej loves to play various types of dull games. He usually asks other people to play with him. He says that playing those games can show his extraordinary wit. Recently Urej takes a great interest in a new game, and Erif Nezorf becomes the victim. To get away from suffering playing such a dull game, Erif Nezorf requests your help. The game uses a rectangular paper that consists of W*H grids. Two players cut the paper into two pieces of rectangular sections in turn. In each turn the player can cut either horizontally or vertically, keeping every grids unbroken. After N turns the paper will be broken into N+1 pieces, and in the later turn the players can choose any piece to cut. If one player cuts out a piece of paper with a single grid, he wins the game. If these two people are both quite clear, you should write a problem to tell whether the one who cut first can win or not.
Input
The input contains multiple test cases. Each test case contains only two integers W and H (2 <= W, H <= 200) in one line, which are the width and height of the original paper.
Output
For each test case, only one line should be printed. If the one who cut first can win the game, print “WIN”, otherwise, print “LOSE”.
Sample Input
2 2
3 2
4 2
Sample Output
LOSE
LOSE
WIN
Source
POJ Monthly,CHEN Shixi(xreborner)
当剪出1*n必输,(2,2),(2,3),(3,2)为最终态,从2枚举计算即可
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3547 Accepted: 1320
Description
Urej loves to play various types of dull games. He usually asks other people to play with him. He says that playing those games can show his extraordinary wit. Recently Urej takes a great interest in a new game, and Erif Nezorf becomes the victim. To get away from suffering playing such a dull game, Erif Nezorf requests your help. The game uses a rectangular paper that consists of W*H grids. Two players cut the paper into two pieces of rectangular sections in turn. In each turn the player can cut either horizontally or vertically, keeping every grids unbroken. After N turns the paper will be broken into N+1 pieces, and in the later turn the players can choose any piece to cut. If one player cuts out a piece of paper with a single grid, he wins the game. If these two people are both quite clear, you should write a problem to tell whether the one who cut first can win or not.
Input
The input contains multiple test cases. Each test case contains only two integers W and H (2 <= W, H <= 200) in one line, which are the width and height of the original paper.
Output
For each test case, only one line should be printed. If the one who cut first can win the game, print “WIN”, otherwise, print “LOSE”.
Sample Input
2 2
3 2
4 2
Sample Output
LOSE
LOSE
WIN
Source
POJ Monthly,CHEN Shixi(xreborner)
当剪出1*n必输,(2,2),(2,3),(3,2)为最终态,从2枚举计算即可
#include<cstdio> #include<cstring> #include<iostream> using namespace std; #define N 205 int mex ;bool b[1<<8]; int SG(int n,int m){ if(mex [m]!=-1) return mex [m]; memset(b,0,sizeof(b)); for(int i=2;i<=n-i;i++) b[SG(i,m)^SG(n-i,m)]=1; for(int i=2;i<=m-i;i++) b[SG(n,i)^SG(n,m-i)]=1; for(int i=0;;i++) if(!b[i]) return mex [m]=i; } int main(){ int n,m;memset(mex,-1,sizeof(mex)); while(scanf("%d%d",&n,&m)!=EOF) if(SG(n,m)) puts("WIN");else puts("LOSE"); return 0; }
相关文章推荐
- infinite scroll和masonry实现的json类型瀑布流
- SpringMVC的两个简单入门的例子(-)
- 让多个Fragment 切换时不重新实例化
- 基本算法prim学习总结性文章
- ZOJ 3926 Parity Modulo P(XJB)
- ZOJ 3923 In the Rain(数学)
- C++中的继承和组合区别使用
- 项目2胖子不想说体重
- 弱网络下的游戏服务器设计
- 文章标题
- 代码才是公司资产
- 新学期新计划
- 第二周项目4-用循环求
- 从源码的角度理解Android消息处理机制
- 第一次上机实践-项目5-斐波那契数列
- 学习python前需要了解的东西——————-python学习流程和资源
- asp.net预定义的HttpModule
- C语言内存管理(内存池)
- HDUACM2016
- Grunt学习——创建子图集