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. WPF Multi-Touch 开发:高级触屏操作(Manipulation)

    原文 WPF Multi-Touch 开发:高级触屏操作(Manipulation) 在上一篇中我们对基础触控操作有了初步了解,本篇将继续介绍触碰控制的高级操作(Manipulation),在高级操作 ...

  2. P65

    #include<stdio.h> #define N 6 main() { char c[N]; int i=0; for(;i<N;c[i]=getchar(),i++); pr ...

  3. asp.net后台对前台脚本的调用

    后台像前台输出要执行的脚本 Response.Write("<script>alert('内容')</script>"); asp.net后台调用前台js脚 ...

  4. Perl 5 教程

    Perl 5 教程 http://www.cbi.pku.edu.cn/chinese/documents/perl/index.htm

  5. 互联网组织的未来:剖析GitHub员工的任性之源(转)

    如果有这么家任性的公司,没有所谓“经理人”这一层,人都在做自己喜欢的事情,并且创造价值,而其他的事情,就顺其自然让他发生.这里能节省多少官僚主义带来的浪费?这样的公司得跑得有多快?得有多少无谓的冲突消 ...

  6. 基于visual Studio2013解决C语言竞赛题之1028平均值

          题目 解决代码及点评 /* 已知有9个数,请求出这些数中的最大值.最小值及平均值,以及有多少个数等于平均值? */ #include<stdio.h> ...

  7. 使用Boost.PropertyTree处理XML、JSON和INI数据

    Boost.PropertyTree 应该是 Boost 1.41.0 开始正式加入 Boost 版本的.目前 ( 2010/02/28 ) 能下到的最新版本是 1.42.0. 主要作用/应用场合 B ...

  8. Twenty Newsgroups Classification任务之二seq2sparse

    seq2sparse对应于mahout中的org.apache.mahout.vectorizer.SparseVectorsFromSequenceFiles,从昨天跑的算法中的任务监控界面可以看到 ...

  9. Javascript 正确用法 二

    好的,废话不多说,接着上篇来. 变量(variables) 始终使用 var keyword来定义变量,假设不这样将会导致 变量全局化,造成污染. //bad superPower = new Sup ...

  10. MFC类中获得其它类指针

    当用VC++的Application Wizard生成除了CDialog Basiced以外的应用程序时,将自动产生视图类.文档类.主帧窗口类.应用程序类等等.一般来说,程序的核心数据及操作在文档类中 ...