博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 2147 SG函数打表(手写也可以) 找规律
阅读量:7036 次
发布时间:2019-06-28

本文共 2433 字,大约阅读时间需要 8 分钟。

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
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
#include
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;}

 

 

转载地址:http://wqjal.baihongyu.com/

你可能感兴趣的文章
有关二分查找的边界思考
查看>>
phpvirtualbox访问Ubuntu虚拟机134-配置详情
查看>>
Java 单元测试利器之 Junit
查看>>
我的友情链接
查看>>
媒体关注OSV智能桌面虚拟化平台
查看>>
安装VMware Workstation提示the msi failed的解决办法
查看>>
MongoDB安装配置
查看>>
使程序在Linux下后台运行
查看>>
webpack构建h5plus多页面移动app
查看>>
Varnish缓存更新策略调试过程
查看>>
unix bsd linux gun 粗略解释
查看>>
shell中特殊符号的用法
查看>>
我的友情链接
查看>>
上传贴图
查看>>
Spring Cloud各组件重试总结
查看>>
【面试题】C语言:模拟实现内存放置函数memset()
查看>>
桌面虚拟化 | 同VDI扭打,IDV要如何补齐短板?
查看>>
CSS Modules 详解及 React 中实践
查看>>
假如Java被报废,未来将会怎样?
查看>>
vue-cli学习——axios实例
查看>>