HDU 2147 kiki's game 博弈

来源:互联网 发布:霜之哀伤淘宝 编辑:程序博客网 时间:2024/04/30 08:16

我已经分不出来这是不是博弈了,反正我是没想到,看了别人的博客,我只想说给人类的智商跪了。。。。。。。。竟然是倒着推出来的

步骤1:将所有终结位置标记为必败点(P点);
步骤2: 将所有一步操作能进入必败点(P点)的位置标记为必胜点(N点)
步骤3:如果从某个点开始的所有一步操作都只能进入必胜点(N点) ,则将该点标记为必败点(P点) ;
步骤4: 如果在步骤3未能找到新的必败(P点),则算法终止;否则,返回到步骤2。


       其实是这样的p只能到n,n跟p相连所以只要第一个人每次都到p第二个人就输定了。反过来也是这样,只要看看终点是不是和起点相同就行相同就输定了。。。

然后根据表格找规律。。

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!
 
#include<iostream>#include<cstdio>#include<string.h>#include<algorithm>#include<math.h>using namespace std;int main(){    int n,m;    while(~scanf("%d %d",&n,&m))    {        if(n==0&&m==0)            break;        if(n%2!=0&&m%2!=0)            printf("What a pity!\n");        else            printf("Wonderful!\n");    }    return 0;}




0 0
原创粉丝点击