Cutting Game poj-2311

题目大意题目链接

注释:略。


想法

我们发现一次操作就是将这个ICG对应游戏图上的一枚棋子变成两枚。

又因为SG定理的存在,记忆化搜索即可。

最后,附上丑陋的代码... ...

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 250
using namespace std;
bool vis[N]; int sg[N][N];
int n,m;
int dp(int x,int y)
{
if(sg[x][y]!=-1) return sg[x][y];
memset(vis,false,sizeof vis);
for(int i=2;i<=x-i;++i) vis[dp(i,y)^dp(x-i,y)]=1;
for(int i=2;i<=y-i;++i) vis[dp(x,i)^dp(x,y-i)]=1;
for(int i=0;;i++) if(!vis[i]) {sg[x][y]=i; return i;}
}
int main()
{
memset(sg,-1,sizeof sg);
sg[2][2]=sg[2][3]=sg[3][2]=0;
while(scanf("%d%d",&n,&m)==2)
{
if(dp(n,m)) puts("WIN");
else puts("LOSE");
}
return 0;
}
/*7
2 2
3 2
4 2
*/

小结:SG定理应用极为广泛。

[poj2311]Cutting Game_博弈论的更多相关文章

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

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

  2. POJ2311 Cutting Game(博弈论)

    总时间限制: 1000ms 内存限制: 65536kB 描述 Urej loves to play various types of dull games. He usually asks other ...

  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. [poj2425]A Chess Game_博弈论

    A Chess Game poj-2425 题目大意:题目链接 注释:略. 想法:这个题就是为什么必须要用记忆化搜索.因为压根就不知道后继是谁. 我们通过SG定理可知:当前游戏的SG值等于所有子游戏的 ...

  8. [poj2505]A multiplication game_博弈论

    A mutiplication game poj-2505 题目大意:给定一个数n和p,两个选手每次可以将p乘上[2,9].最先使得p大于n的选手胜利. 注释:$1\le n\le 429496729 ...

  9. [poj2234]Matces Game_博弈论

    Matches Game poj-2234 题目大意:n堆石子的Nim游戏,anti-SG. 注释:$1\le n\le 20$. 想法:用Colon定理即可.具体见:小约翰的游戏 最后,附上丑陋的代 ...

随机推荐

  1. python 中 str与bytes的转换

    # bytes转字符串方式一 b=b'\xe9\x80\x86\xe7\x81\xab' string=str(b,'utf-8') print(string) # bytes转字符串方式二 b=b' ...

  2. Rabin_Karp(hash) HDOJ 1711 Number Sequence

    题目传送门 /* Rabin_Karp:虽说用KMP更好,但是RK算法好理解.简单说一下RK算法的原理:首先把模式串的哈希值算出来, 在文本串里不断更新模式串的长度的哈希值,若相等,则找到了,否则整个 ...

  3. 使用JS分页 <span> beta 2.0 未封装的分页

    <html> <head> <title>分页</title> <style> #titleDiv{ width:500px; backgr ...

  4. Android4.4以上Uri转换成绝对路径的工具类

    一.Android4.4版本以上Uri地址封装规范: content://com.android.providers.media.documents/document/image%3A659 二.An ...

  5. 6.13---shiro

  6. 6.12---esultMap查询所有

  7. 第5章分布式系统模式 Singleton

    上下文 在某些情况下,特定类型的数据需要提供给应用程序中的其他所有对象使用.在大多数情况下,这种类型的数据在系统中还是唯一的.例如,用户界面只能有一个所有应用程序必须访问的鼠标指针.同样,企业解决方案 ...

  8. 基于SOC方案的嵌入式开发-远程定时设备

    Soc方案实现简单的定时开关灯 http://club.gizwits.com/forum.php?mod=viewthread&tid=7787&highlight=%E5%AE%9 ...

  9. arduino相关资料和网站

    2018-02-0212:59:12 昨天晚上在论坛里看了大半夜,找到了很多有意思的项目,总结一下! http://www.51hei.com/bbs/dpj-105654-1.html   ---贪 ...

  10. Error parsing D:\sdkforas\android-sdk-windows\system-images\android-22\android-wear\x86\devices.xml

    今天在工作过程中向Android Studio中导入一个项目,最后运行出现如下错误: Cannot reload AVD list: cvc-enumeration-valid: Value '280 ...