poj2311 Cutting Game
来源:互联网 发布:背单词软件排名 编辑:程序博客网 时间:2024/05/16 18:19
Cutting Game
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2546 Accepted: 931
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
注意,如果,有个人切成了1*n n*1那个这个人必败,所以每一个人,在切的时候,都会去避开,这样,我们找到前驱,求sg函数值即可!
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int dp[250][250];int getsg(int w,int h){ if(dp[w][h]!=-1)return dp[w][h]; bool vis[10000]; memset(vis,0,sizeof(vis)); for(int i=2;i<=w-i;i++){ dp[i][h]=getsg(i,h); dp[w-i][h]=getsg(w-i,h); vis[dp[i][h]^dp[w-i][h]]=true; } for(int i=2;i<=h-i;i++){ dp[w][i]=getsg(w,i); dp[w][h-i]=getsg(w,h-i); vis[dp[w][i]^dp[w][h-i]]=true; } for(int i=0;;i++) if(!vis[i]) return dp[w][h]=i;}int main(){ int w,h; memset(dp,-1,sizeof(dp)); while(scanf("%d%d",&w,&h)!=EOF){ if(getsg(w,h))printf("WIN\n"); else printf("LOSE\n"); } return 0;}
- poj2311 Cutting Game-----sg
- poj2311 Cutting Game
- POJ2311 Cutting Game (博弈)
- POJ2311 Cutting Game SG函数
- [POJ2311]Cutting Game(博弈)
- 【POJ2311】Cutting Game-SG博弈
- kyeremal-poj2311-Cutting Game-sg函数
- POJ2311——Cutting Game(sg函数)
- [POJ2311]Cutting Game(博弈Multi-SG函数)
- POJ2311 Cutting Game(博弈Multi-SG函数)
- POJ2311
- POJ2311
- poj2311
- POJ 2311 Cutting Game
- POJ-2311-Cutting Game
- POJ 2311 Cutting Game
- POJ - 2311 Cutting Game
- POJ 2311 Cutting Game
- 如何在Android真机上检测是否有Google Map add-on
- [rails]Spork中出现“Could not start Spork server for RSpec”的解决方案
- GCD 的使用 并行串行 队列
- win7 64位下asp不能使用mdb数据库的解决方法
- OpenSTA【开源的Web性能测试软件】
- poj2311 Cutting Game
- CSCOPE 安装和使用方法总结
- VC 数据库编程 ADO入门
- 大行业中的矛盾
- poj 2752 Seek the Name, Seek the Fame (KMP)
- Apache JMeter【对软件做压力测试】
- mysql高效编程阅读摘要--基础篇
- Java高级特性之内存模型(一)
- 成为项目经理必须学习的工具,你知道多少?