欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

HDU 2147 kiki's game 博弈论

程序员文章站 2022-06-09 17:56:08
...
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?
InputInput 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.

OutputIf kiki wins the game printf "Wonderful!", else "What a pity!".
Sample Input
5 3
5 4
6 6
0 0
Sample OutputWhat a pity!
Wonderful!
Wonderful!








传送门hdu崩着= =
套路似乎差不多……按照“全推N为P,能推P为N”的思路,这题左下角为P,然后可以扩展推导。本来可以O(NM)预处理的,但是空间比较小。。那么就找一找这个推导的规律。
HDU 2147 kiki's game 博弈论
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!");
		 else
		if (!(y&1)) puts("Wonderful!");
		 else puts("What a pity!");
	}
	return 0;
}