HDu 2147(博弈)

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

kiki‘s game

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)
Total Submission(s): 8183    Accepted Submission(s): 4866

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!

画出PN图一目了然。

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <math.h>
 4 int main()
 5 {
 6     int n,m;
 7     while (scanf ("%d%d",&n,&m),(n||m))
 8     {
 9         if (n%2&&m%2)
10             printf ("What a pity!\n");
11         else
12             printf ("Wonderful!\n");
13     }
14     return 0;
15 }

时间: 2024-07-31 06:03:32

HDu 2147(博弈)的相关文章

HDU 2147 (博弈) kiki&#39;s game

无奈英语不好又被坑,看到棋子能左移下移左下移,想当然地以为是Wythoff博弈了,=u= 题的意思是说每次只能选一个方向移动一步,所以找找规律就是横纵坐标为奇数的时候是必败状态. 从http://www.cnblogs.com/chaosheng/archive/2012/05/29/2524725.html 盗过来一张图比较好说明: 1 #include <cstdio> 2 3 int main() 4 { 5 int n, m; 6 while(scanf("%d%d"

HDU - 2147 博弈 P/N分析

结论题,很显然和奇偶有关 PS.尝试用dfs写出PN表写崩了 #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<string> #include<vector> #include<stack> #include<

HDU 2147 kiki&#39;s game(博弈图上找规律)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2147 题目大意:给你一个n*m的棋盘,初始位置为(1,m),两人轮流操作,每次只能向下,左,左下这三个方向移动,谁最后无法移动棋子就输掉比赛,问先手是否会获胜. 解题思路:简单题,P/N分析找规律,以(n,m)点为结束点推到起始点,如图: 发现每个田字格的状态都是一样的,因为(n,m)点一定时P态,所以可以得出规律:只有当(m%2==1&&n%2==1)时,先手才会输. 代码: 1 #incl

HDU 2147 kiki&#39;s game(规律,博弈)

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)Total Submission(s): 10763    Accepted Submission(s): 6526 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his

hdu 2147 kiki&#39;s game 博弈

点击打开链接链接 kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others) Total Submission(s): 6933    Accepted Submission(s): 4141 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears

(博弈 sg入门)kiki&#39;s game -- hdu -- 2147

链接: http://acm.hdu.edu.cn/showproblem.php?pid=2147 题意: 在一个n*m的棋盘上,从  (1,m),即右上角开始向左下角走. 下棋者只能往左边(left),左下面(left-underneath),下面(underneath),这三个方格下棋. 最后不能移动的人算输 思路: 手动可以画出必胜态以及必败态的图 可以很容易 找出规律 (1) 所有终结点是必败点(P点): (2)从任何必胜点(N点)操作,至少有一种方法可以进入必败点(P点): (3)无

hdu 2147 kiki&#39;s game, 入门基础博弈

博弈的一些概念: 必败点(P点) : 前一个选手(Previous player)将取胜的位置称为必败点. 必胜点(N点) : 下一个选手(Next player)将取胜的位置称为必胜点. 必败(必胜)点属性 (1) 所有终结点是必败点(P点): (2) 从任何必胜点(N点)操作,至少有一种方法可以进入必败点(P点): (3)无论如何操作, 从必败点(P点)都只能进入必胜点(N点). hdu 2147 kiki's game 题意: 在一个m*n的棋盘内,从(1,m)点出发,每次可以进行的移动是

HDU 2147 kiki&#39;s game (巴什博弈)

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others) Total Submission(s): 5982    Accepted Submission(s): 3552 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his m

HDU 2147 kiki&#39;s game(巴什博弈论)

题目地址:HDU 2147 又是一道NP状态转换的巴什博弈.这题根据NP状态转移最好画个表格,规律就很直观了. 博弈么,从左下角往前推: P→到达该点后,下一个人必败. N→到达该点后,下一个人必胜. 显然,最左下角的点是P. 然后根据经过一步操作可到达必败状态的都是必胜状态,下一步操作都是必胜状态,那么这步操作时必败状态的原则一步步的去画表格就可以了.                                                                        

HDU 2147 —— kiki&#39;s game

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others) 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 th