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

最新文章

  1. 虚拟机上装uoj
  2. python collections模块
  3. iOS开发系列--触摸事件、手势识别、摇晃事件、耳机线控
  4. hue install
  5. 【转】Java日期计算之Joda-Time
  6. [团队项目]sprint3 &amp; 团队贡献分。
  7. PLSA中的EM算法
  8. POJ 2516 最小费用流
  9. poj 2449 Remmarguts&#39; Date(第K短路问题 Dijkstra+A*)
  10. POJ 1930 Dead Fraction
  11. uva 101 by sixleaves
  12. oracle报表开发方案
  13. 个人学习FPGA的初步过程
  14. MVC从路由到Controller运行机制
  15. ORACLE 12c RAC的常用管理命令
  16. spring_06装配bean_2
  17. Vxlan学习笔记——原理(转)
  18. django使用session缓存Redis
  19. JAVA_全局配置文件(配置网址,url等等)_第一种方式
  20. Java基础—异常

热门文章

  1. 数据库迁移 - SQLServer-&gt;MySQL
  2. PHP - Cookie 应用
  3. pthread_detach(pthread_self())
  4. [转]Permission denied: /.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
  5. StrPos,StrScan,
  6. android 图片尺寸 资料
  7. 海量数据存储之Key-Value存储简介
  8. 更改ORACLE 用户的 expired状态
  9. BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )
  10. 托管到GitHub