首页 > 代码库 > ACM-巴什博弈之kiki's game——hdu2147
ACM-巴什博弈之kiki's game——hdu2147
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 |
由于1,6和2,7位置只能向1,7位置移动,所以1,6与2,7为N。
N | ||||||
P | N |
同理,第1列和第7行就可以填充完毕。
P | ||||||
N | ||||||
P | ||||||
N | ||||||
P | ||||||
N | ||||||
P | N | P | N | P | N | P |
P | ||||||
N | ||||||
P | ||||||
N | ||||||
P | ||||||
N | N | |||||
P | N | P | N | P | N | P |
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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。