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. MBR结构解析与fdisk的bash实现

    一.MBR结构解析 首先我们先介绍一些MBR的基本知识基础,再晾图片分析. MBR主要分为三大块各自是: 1.载入引导程序(446K) 2.分区表(64k) 3.标志结束位(2k) 载入引导程序:内容 ...

  2. Windows 编程1

    杀死一个进程 使用命令 system( taskkill /f /im     QQ.exe); 即可. 打开一个进程 使用命令 system("应用程序的位置");   头文件: ...

  3. rf-demos (request)

    *** Settings *** Library RequestsLibrary Library Collections Library XML *** Test Cases *** case1 Cr ...

  4. 这6种思维,学会了你就打败了95%文案!zz

    ​本文笔者为大家讲述了文案高手写文案时最常用的六种思维,这六种思维也都是文案新手容易入的坑. 有的人做了3,5年的文案,还是小白一个.而有的人短短1,2年的时间,却可以成为文案高手. 为什么? 我总结 ...

  5. UiAutomator源代码分析之获取控件信息

    依据上一篇文章<UiAutomator源代码分析之注入事件>開始时提到的计划,这一篇文章我们要分析的是第二点: 怎样获取控件信息 我们在測试脚本中初始化一个UiObject的时候一般是像下 ...

  6. Active Directory虚拟机搭建域控服务器环境

    前言 还是和上一章一样,痛苦过后还是记录下给后来人提供便利为妙. 虚拟机选择:建议Hyper-V或者VMware 系统选择:建议WIindows Server 2003及以上 我这里是使用VMware ...

  7. 图像处理之opencv---常用函数

    http://blog.sina.com.cn/s/blog_9c3fc0730100yzwt.html 很全 http://www.xuebuyuan.com/593449.html cvrepea ...

  8. unity3d开发的android应用中增加AD系统的详细步骤

    unity3d开发的android应用中增加AD系统的详细步骤 博客分类: Unity3d unity3d  Unity3d已经支持android,怎样在程序里增加admob?  试了一下,确实能够, ...

  9. vs2005 未能完成操作。未指定的错误

    具体解决过程是这样的: 1.先把.vcproj 文件剪切到其他地方 2.打开.sln,报错->点“确定”->再点“确定” 3.把 .vcproj 文件 放回来,在vs2008右边的“解决方 ...

  10. Html.DropDownListFor的选项值为字符型问题

    我快要疯了.asp.net mvc的这个DropDownListFor,无论在服务器端如何设置,设置哪个值被选中,结果到了页面输出,选中值根本没有被选中,没有任何一个值被选中,下拉框只冷冰冰地显示一个 ...