POJ2311——Cutting Game(sg函数)
来源:互联网 发布:游戏数据分析师bi 编辑:程序博客网 时间:2024/06/05 20:00
Cutting Game
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3859 Accepted: 1438
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 23 24 2
Sample Output
LOSELOSEWIN
#include<iostream>#include<cstdio>#include<algorithm>#include <queue>#include<cstring>#include <vector>#include <set>using namespace std;const int MAXN = 200 + 10;//记忆化搜索所用函数,初始化为-1int mem[MAXN][MAXN];//计算当前状态sg值int sg(int w,int h){ if(mem[w][h]!=-1) return mem[w][h]; int vis[2000]; memset(vis,0,sizeof(vis)); //竖着切 //把切下来的两张纸看作是两个游戏 //则sg值可以看作是sg1^sg2 //也就是说sg值的异或值等于多个游戏的复合状态 for(int i=2;w-i>=2;i++) vis[sg(i,h)^sg(w-i,h)]=1; //横着切 for(int i=2;h-i>=2;i++) vis[sg(w,i)^sg(w,h-i)]=1; int i=0; for(;;i++) if(vis[i]==0) return mem[w][h]=i;}int main(){ int w,h; //一定要放在循环外面!要不然会T memset(mem,-1,sizeof(mem)); while(scanf("%d%d",&w,&h)!=EOF){ if(sg(w,h)!=0) puts("WIN"); else puts("LOSE"); } return 0;}
0 0
- POJ2311——Cutting Game(sg函数)
- POJ2311 Cutting Game SG函数
- poj2311 Cutting Game-----sg
- kyeremal-poj2311-Cutting Game-sg函数
- 【POJ2311】Cutting Game-SG博弈
- [POJ2311]Cutting Game(博弈Multi-SG函数)
- POJ2311 Cutting Game(博弈Multi-SG函数)
- poj2311 Cutting Game
- POJ2311 Cutting Game (博弈)
- [POJ2311]Cutting Game(博弈)
- poj 2311 Cutting Game(sg函数)
- POJ 2311 Cutting Game (SG函数)
- poj 2311 Cutting Game (sg函数)
- poj 2311 Cutting Game sg函数
- POJ 2311 Cutting Game (sg函数)
- POJ_P2311 Cutting Game(博弈+SG函数)
- POJ 2311 Cutting Game SG函数
- poj 2311 Cutting Game SG函数
- nefu118 n!末尾0的个数
- Android SDK 源码解析项目
- LNMP(linux+nginx+mysql+php)环境搭建_2
- linux学习第九篇:安装Tomcat
- 矩阵相关
- POJ2311——Cutting Game(sg函数)
- 1012. The Best Rank (25)-PAT甲级真题
- 程序员代码面试指南 IT名企算法与数据结构题目最优解 ,左程云著
- CentOS6.5 安装 Nginx
- php中$this的引用计数
- python核心编程学习笔记-2016-08-13-03-授权
- 一个PHP实现的轻量级简单爬虫
- HDU 5783 Divide the Sequence
- PHP学习:单引号和双引号字符串