HDU 2147 kiki's game 博弈

来源:互联网 发布:apache怎么读 编辑:程序博客网 时间:2024/04/27 12:43

kiki's game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others)
Total Submission(s): 6894    Accepted Submission(s): 4123

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!


/*
2147 博弈 
定义:
必胜点(N点):下一个选手将取胜的点(将物品取完)。
必败点(P点):前一个选手取胜的点(此时物品已经取完,或后面某次轮到当前选手时物品已经取完)。


如果这个点是N点 下一个选手就是等下要移动的人必胜
如果这个点是P点 前一个选手人必胜 
属性:
1 、必胜点N点,一定有某种方法到达必败点P点。
2、必败点P点,无论通过什么方法都只能到达必胜点N点。


查看上图 找规律 :n m分别为奇数、偶数的四种情况 
第一个初始P点 不算 所以n-1 m-1看图 
我们查看先移动的人到达的点 若到N下一个点肯定2赢 到达P1赢  
1 n奇 m奇 先移动的只能到达N点 
2.当m为偶数(2种) 先移动的一定可以找到一个P点
3.m为奇数且n为偶数(1种)的矩阵 先移动的一定可以找到一个P点


总之,除了n,m都是奇数是先移动的是输,其他都是2赢
*/
#include<iostream>#include<stdio.h>using namespace std;int main(){int n,m;      while(scanf("%d%d",&n,&m),n+m)      {                   if(n%2==1&&m%2==1)    printf("What a pity!\n");          else                    printf("Wonderful!\n");      }  return 0;} 



0 0
原创粉丝点击