您的位置:首页 > 其它

ACM-巴什博弈之kiki's game——hdu2147

2014-05-01 11:19 225 查看


kiki's game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others)

Total Submission(s): 5987    Accepted Submission(s): 3556


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<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 3
5 4
6 6
0 0

 

Sample Output

What a pity!
Wonderful!
Wonderful!

 

Author

月野兔

 

Source

HDU 2007-11 Programming Contest

 
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2147

百度搜索HDU 巴什博弈出来的题目。。
不知道 巴什博弈,可以戳→http://blog.csdn.net/lttree/article/details/24832747
该题目题意:
给你n*m表格,初始在右上角,每次在上个人移动后的基础上移动一步(向左or向下or向左下)
先到左下角则获胜。
Kiki这个孩纸先走,ZZ后走。
问Kiki是否能赢!
这俩熊孩子,非要玩这种游戏么,耗脑细胞= =。

这题解法,通过建立PN表格,就一目了然。
博弈么,从左下角往前推:
P→到达该点后,下一个人必败。
N→到达该点后,下一个人必胜。
显然,最左下角的点是P

       
       
       
       
       
       
P      
这是7*7的表格,如图1,7位置为P。
由于1,6和2,7位置只能向1,7位置移动,所以1,6与2,7为N。

       
       
       
       
       
N      
PN     
同理,第1列和第7行就可以填充完毕。

P      
N      
P      
N      
P      
N      
PNPNPNP
再反观2,6位置,作为2,6位置上的人,想赢得这场比赛,所以肯定会向1,7移动,因此2,6也是N

P      
N      
P      
N      
P      
NN     
PNPNPNP
每个位置上,都会向赢比赛的趋向走,所以剩余各个点的P、N都可以填充完毕

PNPNPNP
NNNNNNN
PNPNPNP
NNNNNNN
PNPNPNP
NNNNNNN
PNPNPNP
此图填完,可以找到规律:
只有在行列数均为奇数时,为P,其他情况均为N。

所以此题:若行列均为奇数则Kiki无法赢得比赛。

/**************************************
***************************************
*        Author:Tree                  *
*From :http://blog.csdn.net/lttree    *
* Title : kiki's game                 *
*Source: hdu 2147                     *
* Hint  : 巴什博弈                    *
***************************************
**************************************/
#include <stdio.h>
int main()
{
int m,n;
while( scanf("%d%d",&n,&m) && n && m )
{
if( n&1 && m&1 )    printf("What a pity!\n");
else    printf("Wonderful!\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息