HDU 2147 kiki's game kiki的游戏(找P/N状态)

题意:给一个有n*m 个格子的棋盘,将一个硬币放在右上角一格,每次可以往左/下/左下移动一格,碰到不能移动的局面者输。

思路:找P/N状态。先将(n,1)归为P状态,那么能一步到达此位置的有3个位置,分别是其上/右/右上的格子。根据这个规律来找,在整个棋盘的格子上标上P和N。可以发现,棋盘上是有规律的,若提供的n和m皆为奇数,则先手输;否则先手赢。

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     //freopen("input.txt", "r", stdin);
 7     int a, b;
 8     while(cin>>a>>b)
 9     {
10         if(!a&&!b)  break;
11         if( a&1 && b&1 )    printf("What a pity!\n");
12         else    printf("Wonderful!\n");
13     }
14     return 0;
15 }

AC代码

HDU 2147 kiki's game kiki的游戏(找P/N状态)

时间: 2024-12-29 10:55:33

HDU 2147 kiki's game kiki的游戏(找P/N状态)的相关文章

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

hdu 2147 kiki&#39;s game(DP(SG)打表找规律)

题意: n*m的棋盘,一枚硬币右上角,每人每次可将硬币移向三个方向之一(一格单位):左边,下边,左下边. 无法移动硬币的人负. 给出n和m,问,先手胜还是后手胜. 数据范围: n, m (0<n,m<=2000) 思路: dp[i][j]=0,说明从(i,j)这个点到时左下角先手败.dp[i][j]=1则先手胜. 然后记忆搜.但是记忆搜会超时. 搜完把整张表打出来,发现规律了,,,,然后,,,代码剩几行了. 代码: ///打表观察 /* int f[2005][2005]; int go(in

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

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)Total Submission(s): 10656    Accepted Submission(s): 6455 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/10000 K (Java/Others)http://acm.hdu.edu.cn/showproblem.php?pid=2147 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she ju

(博弈 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)无