(博弈)NP图法kiki's game

来源:互联网 发布:h5网页js小游戏开发 编辑:程序博客网 时间:2024/04/28 17:36

                                   kiki's game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)
Total Submission(s): 9543    Accepted Submission(s): 5725


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 35 46 60 0
 

Sample Output
What a pity!Wonderful!Wonderful!
在一个n*m的棋盘上,两个人将一颗棋子从右上角只能通过往左,下,左下方向移动,如果谁先不能移动,谁就输了。

定义:

必胜点(N点):下一个选手将取胜的点(将物品取完)。

必败点(P点):前一个选手取胜的点(此时物品已经取完,或后面某次轮到当前选手时物品已经取完)。

属性:

1 、必胜点N点,一定有某种方法到达必败点P点。

2、必败点P点,无论通过什么方法都只能到达必胜点N点。

     即:  当m为偶数 或  m为奇数且n为偶数的矩阵,先移硬币的人一定可以找到一个必败点,即先移的人一定最后可以到达(n,1)

              当m、n均为奇数时,先移动的只能到达必胜点(即下一个选手取胜)

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

0 0
原创粉丝点击