题意:给定一个长方形纸张,每次只能水平或者垂直切,如果切到1*1的方格就胜,问先手胜还是负。

析:根据Nim游戏可知,我们可以分别求出每个子游戏的和,就是答案,所以我们就枚举每一种切法,然后求出SG函数,那么就能得到答案。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 200 + 10;
const int mod = 1e6 + 10;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int dp[maxn][maxn]; int dfs(int r, int c){
int &ans = dp[r][c];
if(ans >= 0) return ans;
set<int> sets;
for(int i = 2; r - i > 1; ++i) sets.insert(dfs(r-i, c) ^ dfs(i, c));
for(int i = 2; c - i > 1; ++i) sets.insert(dfs(r, i) ^ dfs(r, c-i));
int res = 0;
while(sets.count(res)) ++res;
return ans = res;
} int main(){
memset(dp, -1, sizeof dp);
while(scanf("%d %d", &m, &n) == 2){
printf("%s\n", dfs(m, n) ? "WIN" : "LOSE");
}
return 0;
}

  

POJ 2311 Cutting Game (博弈)的更多相关文章

  1. POJ 2311 Cutting Game(Nim博弈-sg函数/记忆化搜索)

    Cutting Game 题意: 有一张被分成 w*h 的格子的长方形纸张,两人轮流沿着格子的边界水平或垂直切割,将纸张分割成两部分.切割了n次之后就得到了n+1张纸,每次都可以选择切得的某一张纸再进 ...

  2. POJ 2311 Cutting Game(二维SG+Multi-Nim)

    Cutting Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4798   Accepted: 1756 Desc ...

  3. POJ 2311 Cutting Game (Multi-Nim)

    [题目链接] http://poj.org/problem?id=2311 [题目大意] 给出一张n*m的纸,每次可以在一张纸上面切一刀将其分为两半 谁先切出1*1的小纸片谁就赢了, [题解] 如果切 ...

  4. POJ 2311 Cutting Game(SG函数)

    Cutting Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4806   Accepted: 1760 Desc ...

  5. poj 2311 Cutting Game 博弈论

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

  6. POJ 2311 Cutting Game(SG+记忆化)

    题目链接 #include<iostream> #include<cstdio> #include<cstring> using namespace std; ][ ...

  7. POJ 2311 Cutting Game [Multi-SG?]

    传送门 题意:n*m的纸片,一次切成两份,谁先切出1*1谁胜 Multi-SG? 不太一样啊 本题的要求是后继游戏中任意游戏获胜就可以了.... 这时候,如果游戏者发现某一单一游戏他必败他就不会再玩了 ...

  8. POJ 2311 Cutting Game(SG函数)

    题目描述 意思就是说两个人轮流剪纸片,直到有一个人剪出1*1的方格就算这个人赢了.然后给出纸片的长和宽,求先手会赢还是会输 (1<=n,m<=200) 题解 看了一眼,这不是裸的SG吗 啪 ...

  9. poj 2311 Cutting Game (SG)

    题意: 有一张W*H的纸片. 每人每次可以横着撕或者竖着撕,先撕出1*1那一方胜. 数据范围: W and H (2 <= W, H <= 200) 思路: 很好抽象出游戏图的模型,用SG ...

随机推荐

  1. ES中DSL查询相关

    elasticsearch中的API:http://www.cnblogs.com/yjf512/p/4862992.html elasticsearch查询系列:http://blog.csdn.n ...

  2. mysql insert返回主键

    使用mybatis的话,很方便. 使用useGeneratedKeys和keyProperty,keyProperty是插入的java对象的属性名,不是表的字段名. 这样,在插入该条记录之后,生成的主 ...

  3. Error524 源站处理超时 Error 524: A timeout occurred

    https://su.baidu.com/helps/index.html#/4/5a61e4b5b34f697f13234a5b Error524 源站处理超时 更新时间:2018-01-19 20 ...

  4. To discount or not to discount in reinforcement learning: A case study comparing R learning and Q learning

    https://www.cs.cmu.edu/afs/cs/project/jair/pub/volume4/kaelbling96a-html/node26.html [平均-打折奖励] Schwa ...

  5. hashMap的线程不安全

    hashMap是非线程安全的,表现在两种情况下: 1 扩容: t1线程对map进行扩容,此时t2线程来读取数据,原本要读取位置为2的元素,扩容后此元素位置未必是2,则出现读取错误数据. 2 hash碰 ...

  6. 使用python转换编码格式

    之前有写过一个使用powershell转换文档格式的方法,然而因为powershell支持不是很全,所以并不好用.这里使用python再做一个. 思路 检测源码格式,如果不是utf8,则进行转换,否则 ...

  7. Ruby 仿 C 结构体:CStruct 的一些例子

    1. [代码]最简单的例子     # CStruct Examplesrequire 'cstruct' # example:# struct Point in C\C++        (32-b ...

  8. 三年java软件工程师应有的技技能

    摘要:http://blog.csdn.net/jieinasiainfo/article/details/51177729 http://blog.csdn.net/kangqianglong/ar ...

  9. html5常用模板下载网站

    html5常用模板下载网站 开创者素材.站长素材.模板之家 推荐葡萄家园素材网,他们网页模板栏目有个HTML模板,很多静态源码.应该是你所需要的. html静态页面模板 还是服饰素材啊 朋友 设计云 ...

  10. listen 73

    Give Time to Feel Less Time-Squeeze Meetings, calls, kids, dogs, errands, exercise—and all those ema ...