Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she just playes the checkerboard game.The size of the chesserboard is n*m.First of all, a coin is placed in the top right corner(1,m). Each time one people can move the coin into the left, the underneath or the left-underneath blank space.The person who can't make a move will lose the game. kiki plays it with ZZ.The game always starts with kiki. If both play perfectly, who will win the game? 

InputInput contains multiple test cases. Each line contains two integer n, m (0<n,m<=2000). The input is terminated when n=0 and m=0.

OutputIf kiki wins the game printf "Wonderful!", else "What a pity!". 
Sample Input

5 3
5 4
6 6
0 0

Sample Output

What a pity!
Wonderful!
Wonderful!

题意:

开始棋子在(n,m),每次可向左,或向上,或左上走一步。走到(1,1)者胜利。

没有什么好的思路,SG函数转移没问题,但是MLE,所以打表找规律。

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int SG[maxn+][maxn+];
int ex[maxn],n,m;
void solve()
{
int times=;
for(int i=;i<=maxn;i++)
for(int j=;j<=maxn;j++)
{
if(i==&&j==){
SG[i][j]=;
continue;
}
times++;
if(i>) ex[SG[i-][j]]=times;
if(j>) ex[SG[i][j-]]=times;
if(i>&&j>) ex[SG[i-][j-]]=times;
for(int k=;k<;k++){
if(ex[k]!=times) {
SG[i][j]=k; break;
}
}
}
}
int main()
{
solve();
for(int i=;i<=;i++){
for(int j=;j<=;j++){
if(SG[i][j]) printf("P ");
else printf("N ");
}
printf("\n");
}
}
N P N P N P N P N P
P P P P P P P P P P
N P N P N P N P N P
P P P P P P P P P P
N P N P N P N P N P
P P P P P P P P P P
N P N P N P N P N P
P P P P P P P P P P
N P N P N P N P N P
P P P P P P P P P P Process exited normally.
Press any key to continue . . .

发现n和m都为奇数点才是必胜N态。

但是至于证明,我暂时还没想到。

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int main()
{
while(~scanf("%d%d",&n,&m)){
if(n==&&m==) return ;
n%=; m%=;
if(n==||m==) printf("Wonderful!\n");
else printf("What a pity!\n");
} return ;
}

一个小时后,突然想起10000kb的内存,用bool应该没问题,果然。

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
bool SG[maxn+][maxn+];
int n,m;
void solve()
{
for(int i=;i<=maxn;i++)
for(int j=;j<=maxn;j++)
{
if(i==&&j==){
SG[i][j]=false;
continue;
}
if(i>&&!SG[i-][j]) SG[i][j]=true;
if(j>&&!SG[i][j-]) SG[i][j]=true;
if(i>&&j>&&!SG[i-][j-]) SG[i][j]=true;
}
}
int main()
{
solve();
while(~scanf("%d%d",&n,&m)){
if(n==&&m==) return ;
if(SG[n][m]) printf("Wonderful!\n");
else printf("What a pity!\n");
} return ;
}

HDU2147 kiki's game (SG表找规律)的更多相关文章

  1. BZOJ 1228 E&G(sg函数+找规律)

    把一对石子堆看出一个子游戏.打出子游戏的sg表找规律.. 这个规律我是一定找不出来的... 对于i,j,如果 (i-1)%pow(2,k+1) < pow(2,k) (j-1)%pow(2,k+ ...

  2. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  3. HDU 5795 A Simple Nim(SG打表找规律)

    SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...

  4. hdu 3032 Nim or not Nim? (sg函数打表找规律)

    题意:有N堆石子,每堆有s[i]个,Alice和Bob两人轮流取石子,可以从一堆中取任意多的石子,也可以把一堆石子分成两小堆 Alice先取,问谁能获胜 思路:首先观察这道题的数据范围  1 ≤ N ...

  5. HDU 3032 (SG打表找规律)

    题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围 ...

  6. HDU-4664 Triangulation 博弈,SG函数找规律

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4664 题意:一个平面上有n个点(一个凸多边形的顶点),每次可以连接一个平面上的两个点(不能和已经连接的 ...

  7. HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)

    Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  8. hdu_5795_A Simple Nim(打表找规律的博弈)

    题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...

  9. HDU 3032 multi-sg 打表找规律

    普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...

随机推荐

  1. squirrelsql安装

    官网下载安装,第一次安装mac上,失败,后续重启mac看下.重启完后,还是起不来,估计和某些环境冲突,或者缺少环境 使用squirrelsql如何连接hive? http://lxw1234.com/ ...

  2. [反汇编练习] 160个CrackMe之031

    [反汇编练习] 160个CrackMe之031. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  3. 转:WebRTC技术及应用2 – NAT穿越技术的使用

    评:webrtc自带的打洞,穿透协议. 转: http://www.unclekevin.org/?p=924 959 views WebRTC技术及应用2 – NAT穿越技术的使用 发表回复 (题图 ...

  4. FreeBSD 8

    FreeBSD 8.0的安装过程和7.2区别不大.先在FreeBSD官方网站上下载安装镜像,我一般都下载DVD的ISO,也有人爱好下最小的安装包,然后通过FTP或HTTP方式从网上下载各个程序包. 这 ...

  5. XSS过滤

    XSS过滤封装用法 封装到app01/form.py文件中进行验证 from django.forms import Form,widgets,fields class ArticleForm(For ...

  6. Python+Selenium框架unittest执行脚本方法之discover()方法

    继续接着介绍,如何利用unittest管理和执行测试用例的问题,这里我们还是利用之前已经有的三条测试用例,如果你跳过了前面文章,请回到框架设计篇的第八篇和第七篇,里面有相关测试类的文件.本文来介绍,如 ...

  7. 【转】Linux上的free命令详解

    解释一下Linux上free命令的输出.默认输出是KB,可以用free -m则输出是MB 下面是free的运行结果,一共有4行.为了方便说明,我加上了列号.这样可以把free的输出看成一个二维数组FO ...

  8. [转]eclipse查看某个java类属于哪个jar包

    原文地址:https://blog.csdn.net/csdnliuxin123524/article/details/73572836 在eclipse界面直接按ctrl+shift+t,弹出以下界 ...

  9. angular 复选框checkBox多选的应用

    应用场景是这样的,后台返回的数据在页面上复选框的形式repeat出来 可能会有两种需求: 第一:后台返回的只有项,而没有默认选中状态(全是待选状态) 这种情况相对简单只要repeat出相应选项 第二: ...

  10. 如何求文件File的字节数

      [java]代码库 import java.io.*;   /**  * 获取文件的字节数  */   class FileInputStreamS {     public static voi ...