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. MSSQL奇技淫巧

    MSSQL:获得库每个表的记录数和容量 sp_msforeachtable是MS未公开的存储过程: exec sp_msforeachtable @command1="print '?'&q ...

  2. C#文件上传和文件下载

    #region 文件上传 private void UpLoadFile(string fileName, string fileNamePath, string uriString) { ); if ...

  3. 10-IOSCore - 应用间通信、本地通知

    一.应用间通信 URL 调用系统服务: tel:11111 sms:xxx@163.com http:// URL深入 类型://主机:端口/地址?参数 label框等于文字大小快捷键:command ...

  4. RVCT的Linux环境变量配置 ARM® RVDS™ 4.1(b713)

    下载解压 armrvds.tar.gz到/opt 下 在自己的build.sh下导入RVCT的环境变量配置ARM® RVDS™4.1(b713): export ARMROOT=/opt/armrvd ...

  5. hdu4620 Fruit Ninja Extreme

    Fruit Ninja Extreme Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  6. android开发隐藏了actionbar仍然短暂闪现的解决方法

    有时候我们在代码里隐藏了actionbar,在打开应用时,仍然短暂闪现下actionbar,用户体验很不好.   最简单的方法是 在AndroidManifest.xml中设置主题中配置不显示titl ...

  7. 普通图片转ascii码字符图

    效果图 基本思路 把图片每个像素点的信息拿出来,最重要的是拿到rgb的值 把每个像素点由rgb转成灰度图像,即0-255 给0-255分级,把每个等级的像素点转换成ascii码,完成 实现 第一步:获 ...

  8. 将某个MySQL库中的UTF8字符列都转成GBK格式

    DELIMITER $$ DROP PROCEDURE IF EXISTS `dba`.`Proc_ChangeCharacter2GBK`$$ CREATE DEFINER=`root`@`%` P ...

  9. CorePlot学习零---安装

    刚開始接触CorePlot时,网上搜到非常多相关文章,解说怎样安装这个第三方库,到眼下阶段该库的版本号已经到了1.5了,可是在github上你能够看到他的安装方法,只是为啥就没有codpod来安装呢? ...

  10. 改动导航栏上返回button上的字,比如把back改动为返回

    改动导航栏上返回button上的字,比如把back改动为返回 注意:这个须要在跳转之前到视图控制器中写,而不是在跳转之后到控制器中写 UIBarButtonItem *backIetm = [[UIB ...