hdu2147 kiki's game(巴什博弈java)
題目鏈接
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先走。
分析一下走法:
先考慮走直線,不難發(fā)現(xiàn):如果走直線,向左,向下。從左下角開始找P/N點。畫出圖。
- 必敗點(P點) :前一個選手(Previous player)將取勝的位置稱為必敗點。
- 必勝點(N點) :下一個選手(Next player)將取勝的位置稱為必勝點。
最后一個點(左下角必敗),因為他的前一個人走到該點他就輸了。
相反,他的附近三個點都是必勝點,因為這個人走一步就贏了。
所以分析pn圖可以發(fā)現(xiàn)(n%2==0)或者(m%2= =0)都是 必勝的。
附上代碼如下:
總結
以上是生活随笔為你收集整理的hdu2147 kiki's game(巴什博弈java)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu1007最近点对问题(分冶java
- 下一篇: nivicat复制mysql数据库[Er