标签:acm 巴什博弈 kikis game hdu2147 pn表格构建
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
Sample Output
What a pity!
Wonderful!
Wonderful!
Author
月野兔
Source
百度搜索HDU 巴什博弈出来的题目。。
该题目题意:
给你n*m表格,初始在右上角,每次在上个人移动后的基础上移动一步(向左or向下or向左下)
先到左下角则获胜。
Kiki这个孩纸先走,ZZ后走。
问Kiki是否能赢!
这俩熊孩子,非要玩这种游戏么,耗脑细胞= =。
这题解法,通过建立PN表格,就一目了然。
博弈么,从左下角往前推:
P→到达该点后,下一个人必败。
N→到达该点后,下一个人必胜。
显然,最左下角的点是P
由于1,6和2,7位置只能向1,7位置移动,所以1,6与2,7为N。
同理,第1列和第7行就可以填充完毕。
P |
|
|
|
|
|
|
N |
|
|
|
|
|
|
P |
|
|
|
|
|
|
N |
|
|
|
|
|
|
P |
|
|
|
|
|
|
N |
|
|
|
|
|
|
P |
N |
P |
N |
P |
N |
P |
再反观2,6位置,作为2,6位置上的人,想赢得这场比赛,所以肯定会向1,7移动,因此2,6也是N
P |
|
|
|
|
|
|
N |
|
|
|
|
|
|
P |
|
|
|
|
|
|
N |
|
|
|
|
|
|
P |
|
|
|
|
|
|
N |
N |
|
|
|
|
|
P |
N |
P |
N |
P |
N |
P |
每个位置上,都会向赢比赛的趋向走,所以剩余各个点的P、N都可以填充完毕
P |
N |
P |
N |
P |
N |
P |
N |
N |
N |
N |
N |
N |
N |
P |
N |
P |
N |
P |
N |
P |
N |
N |
N |
N |
N |
N |
N |
P |
N |
P |
N |
P |
N |
P |
N |
N |
N |
N |
N |
N |
N |
P |
N |
P |
N |
P |
N |
P |
此图填完,可以找到规律:
只有在行列数均为奇数时,为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;
}
ACM-巴什博弈之kiki's game——hdu2147,布布扣,bubuko.com
ACM-巴什博弈之kiki's game——hdu2147
标签:acm 巴什博弈 kikis game hdu2147 pn表格构建
原文地址:http://blog.csdn.net/lttree/article/details/24836839