HDU 2147 kiki's game 博弈论

来源:互联网 发布:b2b源码授权费用 编辑:程序博客网 时间:2024/05/16 09:34
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!








传送门
hdu崩着= =

套路似乎差不多……按照“全推N为P,能推P为N”的思路,
这题左下角为P,然后可以扩展推导。
本来可以O(NM)预处理的,但是空间比较小。。
那么就找一找这个推导的规律。


X是必败态,O是必胜态;
那么画一画就可以出来了。
规律非常明显吧……




#include<bits/stdc++.h>using namespace std;int main(){int x,y;while (1){scanf("%d%d",&x,&y);if (!x) break;if (!(x&1)) puts("Wonderful!"); elseif (!(y&1)) puts("Wonderful!"); else puts("What a pity!");}return 0;}

原创粉丝点击