总时间限制: 1000ms 内存限制: 65536kB

描述

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.

输入

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.

输出

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".

样例输入

2 2

3 2

4 2

样例输出

LOSE

LOSE

WIN

来源

POJ Monthly,CHEN Shixi(xreborner)

题解:

用sg函数做,还套了个记忆化

切成两半以后,返回的sg值就是两个数的异或。如果有两个必胜,用掉一个,别人再用一个,你就是两个必败了

注意点:为什么要从2开始枚举?

因为如果是1了,先手必胜(非(1,1),可是我的初始化没有设置这种情况,就会出现-1

#include <bits/stdc++.h>
#define int long long
using namespace std;
int sg[230][230], x, y, tong[1200];
bool vis[230][230];
int find(int x, int y) {
if(sg[x][y]!=-1) return sg[x][y];
memset(tong, 0, sizeof tong);
for (int i = 2; i <= x-i; i++)
tong[(find(i, y)) ^ (find(x - i, y))]=1;
for (int i = 2; i <= y-i; i++)
tong[(find(x, i)) ^ (find(x, y - i))]=1;
for (int i = 0; i < 1200; i++)
if (!tong[i]) {
sg[x][y] = i;
return i;
}
}
signed main() {
memset(sg,-1,sizeof sg);
sg[2][2] = sg[2][3] = sg[3][2] = 0;
while (scanf("%lld%lld", &x, &y) != EOF) {
if (!find(x, y))
puts("LOSE");
else
puts("WIN");
}
return 0;
}

POJ2311 Cutting Game(博弈论)的更多相关文章

  1. [poj2311]Cutting Game_博弈论

    Cutting Game poj-2311 题目大意:题目链接 注释:略. 想法: 我们发现一次操作就是将这个ICG对应游戏图上的一枚棋子变成两枚. 又因为SG定理的存在,记忆化搜索即可. 最后,附上 ...

  2. $POJ2311\ Cutting\ Game$ 博弈论

    正解:博弈论 解题报告: 传送门! 首先看到说,谁先$balabala$,因为$SG$函数是无法解决这类问题的,于是考虑转化成"不能操作者赢/输"的问题,不难想到先剪出$1\cdo ...

  3. 【博弈论】【SG函数】poj2311 Cutting Game

    由于异或运算满足结合律,我们把当前状态的SG函数定义为 它所能切割成的所有纸片对的两两异或和之外的最小非负整数. #include<cstdio> #include<set> ...

  4. POJ2311 Cutting Game 博弈 SG函数

    Cutting Game Description Urej loves to play various types of dull games. He usually asks other peopl ...

  5. POJ2311 Cutting Game

    题意 Language:Default Cutting Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6007 Acc ...

  6. poj 2311 Cutting Game 博弈论

    思路:求SG函数!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<c ...

  7. 博弈论BOSS

    基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...

  8. 博弈问题之SG函数博弈小结

    SG函数: 给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移 动者判负.事实上,这个游戏可以认为是所有Impartial Combinatorial Ga ...

  9. 【Mark】博弈类题目小结(HDU,POJ,ZOJ)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...

随机推荐

  1. 微服务&spring cloud架构系列汇总

    为了方便查找,把微服务&微服务架构之spring cloud架构系列文章按时间正序整理了一下,记录如下:   1. 微服务架构之spring cloud 介绍 2. 微服务架构之spring ...

  2. 微信小程序-02-项目文件之间配合和调用关系

    微信小程序-02-项目文件之间配合和调用关系 我就不说那么多了,我是从官方文档拷贝的,然后加上一些自己的笔记,不喜勿喷 官方文档:https://developers.weixin.qq.com/mi ...

  3. linux命令大全比较完整

    转:https://www.cnblogs.com/yjd_hycf_space/p/7730690.html 最近都在和Linux打交道,感觉还不错.我觉得Linux相比windows比较麻烦的就是 ...

  4. AndroidUI多线程网络请求更新导致BUG

    昨天发现一个问题,以前做好的UI列表不用正常显示了,必须,下拉一下,才能加载内容,以前是页面自动加载第一屏幕的. 这个就不好了,只是给页面加了一个按钮啊,不应该造成这么大的问题. 按钮就是设置了一个位 ...

  5. 常见网络编程面试题答案征集与面试题(收集) ZZ 【网络编程】

    http://www.cnblogs.com/wickedboy237/archive/2013/05/12/3074362.html 1:tcp和udp的区别2:流量控制和拥塞控制的实现机制3:滑动 ...

  6. Mybatis学习---Mybatis分页插件 - PageHelper

    1. Mybatis分页插件 - PageHelper说明 如果你也在用Mybatis,建议尝试该分页插件,这个一定是最方便使用的分页插件. 该插件目前支持Oracle,Mysql,MariaDB,S ...

  7. C++通过Callback向C#传递数据

    现在比较流行C#与C++融合:C#做GUI,开发效率高,C++做运算,运行效率高,二者兼得. 但是C++与C#必然存在数据交互,C#与C++dll的数据交互从来都是一个让人头疼的问题. 从调用方式看也 ...

  8. 10G client连接数据库

    tnsnames.ora文件中的名字一定要顶格写(前面不留空格),不然连接时会如下报错. 已使用的参数文件:F:\oracle\product\10.2.0\client_1\network\admi ...

  9. TCP/IP 协议图--计算机网络体系结构分层

    计算机网络体系结构分层   计算机网络体系结构分层 不难看出,TCP/IP 与 OSI 在分层模块上稍有区别.OSI 参考模型注重“通信协议必要的功能是什么”,而 TCP/IP 则更强调“在计算机上实 ...

  10. app.config/web.config配置文件增删改

    一.概述 应用程序配置文件,对于asp.net是 web.config,对于WINFORM程序是 App.Config(ExeName.exe.config). 配置文件,对于程序本身来说,就是基础和 ...