kiki's game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others)
Total Submission(s): 4972    Accepted Submission(s): 2908

Problem Description
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?

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

 
Output
If 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!
 
Author
月野兔
 
Source
 
Recommend
威士忌

题意:

在一个n*m的棋盘上,从 (1,m),即右上角开始向左下角走。

下棋者只能往左边(left),左下面(left-underneath),下面(underneath),这三个方格下棋。

最后不能移动的人算输

思路:

手动可以画出必胜态以及必败态的图

可以很容易 找出规律

(1) 所有终结点是必败点(P点);

(2)从任何必胜点(N点)操作,至少有一种方法可以进入必败点(P点);

(3)无论如何操作,从必败点(P点)都只能进入必胜点(N点).

由此可知 10*10之内的为   (完全可以手写出来)

NNNNNNNNNN
PNPNPNPNPN
NNNNNNNNNN
PNPNPNPNPN
NNNNNNNNNN
PNPNPNPNPN
NNNNNNNNNN
PNPNPNPNPN
NNNNNNNNNN
PNPNPNPNPN

可以看出  NN

PN  这样的规律    之后很容易知道怎么做了

#include<stdio.h>
int main()
{
int n,m;
while(scanf("%d%d",&n,&m))
{
if(n==0&&m==0)break;
if(n%2==1&&m%2==1)printf("What a pity!\n");
else printf("Wonderful!\n");
}
return 0;
}

还可以用SG函数打表找出我们所要的结果NP 图

#include<stdio.h>
#include<string.h>
const int sz=200;
int SG[sz][sz];
int dir[3][2]={-1,0,0,1,-1,1};
int n,m;
void get_sg()
{
int i,j;
memset(SG,0,sizeof(SG));
for(i=n;i>=1;i--)
for(j=1;j<=m;j++)
{
if(!SG[i][j])
for(int k=0;k<3;k++)
{
int xx=i+dir[k][0];
int yy=j+dir[k][1];
if(xx>=1&&xx<=n&&yy>=1&&yy<=m)
{
SG[xx][yy]=1;
}
}
}
}
int main()
{
int i,j; while(scanf("%d %d",&n,&m)!=EOF)
{
get_sg();
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++) if(SG[i][j]==1) printf("N"); else printf("P");
printf("\n");
}
if(SG[1][m]==1)
{
printf("Wonderful!\n");
}
else printf("What a pity!\n");
}
return 0;
}

hdu 2147 SG函数打表(手写也可以) 找规律的更多相关文章

  1. hdu1848(sg函数打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 题意:中文题诶- 思路:直接sg函数打表就好了 代码: #include <iostrea ...

  2. UPCOJ9526(SG函数打表,nim游戏异或规则)

    #include<bits/stdc++.h>using namespace std;int f[1007],SG[1007],S[1007];//f为可以选取的石头个数,SG为sg函数, ...

  3. bzoj 1228 [SDOI2009]E&D SG函数打表 找规律

    题目链接 Description 桌子上有2n 堆石子,编号为1..2n.将第2k-1 堆与第2k 堆(1 ≤ k ≤ n)为同一组.第i堆的石子个数用一个正整数Si表示.一次分割操作指的是,从桌子上 ...

  4. 51 nod1067 Bash游戏 V2(sg函数打表)

    1067 Bash游戏 V2 1.0 秒 131,072.0 KB 5 分 1级题   有一堆石子共有N个.A B两个人轮流拿,A先拿.每次只能拿1,3,4颗,拿到最后1颗石子的人获胜.假设A B都非 ...

  5. Educational Codeforces Round 68 (Rated for Div. 2)D(SG函数打表,找规律)

    #include<bits/stdc++.h>using namespace std;int sg[1007];int main(){ int t; cin>>t; while ...

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

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

  7. hdu 1536 SG函数模板题

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  8. Nowcoder 挑战赛23 B 游戏 ( NIM博弈、SG函数打表 )

    题目链接 题意 : 中文题.点链接 分析 : 前置技能是 SG 函数.NIM博弈变形 每次可取石子是约数的情况下.那么就要打出 SG 函数 才可以去通过异或操作判断一个局面的胜负 打 SG 函数的时候 ...

  9. HDU 5183 Negative and Positive (NP) (手写哈希)

    题目链接:HDU 5183 Problem Description When given an array \((a_0,a_1,a_2,⋯a_{n−1})\) and an integer \(K\ ...

随机推荐

  1. arm:c语言和汇编混合编程

    仅作演示. 1.C和汇编可相互调用,汇编子函数格式参考 汇编:普通的函数调用的汇编代码解析 http://www.cnblogs.com/mylinux/p/4139972.html 本文演示了 : ...

  2. QPointer更安全,QScopedPointer自动出范围就删除,QSharedDataPointer帮助实现隐式共享

    http://blog.csdn.net/hai200501019/article/details/8474582http://blog.csdn.net/hai200501019/article/d ...

  3. lokijs

    http://lokijs.org/#/ 500,000+ 1.1M ops/s. A fast, in-memory document-oriented datastore for node.js, ...

  4. jsp各部分编码的含义

    服务器JSP编码 pageEncoding 是jsp文件本身的编码, 第一阶段是jsp编译成.java,它会根据pageEncoding的设定读取jsp,(jsp文件的编码,pageEncoding是 ...

  5. MinGW介绍与使用

    3.1:MinGW 是什么? MinGW 提供了一套简单方便的Windows下的基于GCC 程序开发环境.MinGW 收集了一系列免费的Windows 使用的头文件和库文件:同时整合了GNU ( ht ...

  6. ImageMagick 压缩图片 方法

    Images as a percentage of page weight for the Alexa top 10 global web sites  图片在站点所占的比重越来越重.更好的优化图片能 ...

  7. Linux系统中如何添加自己的库文件路径

    库文件在连接(静态库和共享库)和运行(仅限于使用共享库的程序)时被使用,其搜索路径是在系统中进行设置的.一般 Linux 系统把 /lib 和 /usr/lib 两个目录作为默认的库搜索路径,所以使用 ...

  8. 三种java 去掉字符串中的重复字符函数

    三种java 去掉字符串中的重复字符函数 public static void main(string[] args) { system.out.println(removerepeatedchar( ...

  9. Debian安装Nexus

    前置条件 安装jdk (如果使用 nexus-2.6 以上版本需要jdk7) 1 apt-get install openjdk-6-jre / apt-get install openjdk-6-j ...

  10. 解决外网与内网或内网之间的通信,NAT穿透

    在网络编码中会发现程序在局域网中是可以适用的,但是在外网与内网之间和内网与内网之间就不可行.问题就在于NAT.首先介绍下NAT. NAT的作用NAT(Network Address Translato ...