题目链接 kiki’s game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/10000 K (Java/Others)
Total Submission(s): 13497 Accepted Submission(s): 8238
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<=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 3
5 4
6 6
0 0
Sample Output
What a pity!
Wonderful!
Wonderful!
意思是一个棋子只能往左面,下面,或者左下走。不能走的那个输。kiki先走。
分析一下走法:
先考虑走直线,不难发现:如果走直线,向左,向下。从左下角开始找P/N点。画出图。
- 必败点(P点) :前一个选手(Previous player)将取胜的位置称为必败点。
- 必胜点(N点) :下一个选手(Next player)将取胜的位置称为必胜点。
最后一个点(左下角必败),因为他的前一个人走到该点他就输了。
相反,他的附近三个点都是必胜点,因为这个人走一步就赢了。
所以分析pn图可以发现(n%2==0)或者(m%2= =0)都是 必胜的。
附上代码如下: