HDU 1564 Play a game && HDU 2147 kiki's game

HDU 1564 Play a game题意:

棋盘的大小是n*n。一块石头被放在一个角落的广场上。他们交替进行,8600人先走。每次,玩家可以将石头水平或垂直移动到一个未访问的邻居广场。谁不采取行动,谁就会输掉这场比赛。如果双方都打得很好,谁将赢得比赛?

题解:

三角形代表起始位置,虽然不是右上角但是解题都差不多

如果n为偶数,那么所有格子可以被2*1的砖块覆盖掉。

这样先手每次都移动到当前1*2的另外一块。先手必赢。

如果n为奇数。出了起始那个店,其余点都可以被覆盖。

代码:

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cstring>
 5 #define MAXN 5005
 6 using namespace std;
 7 int main()
 8 {
 9     int n;
10     while(~scanf("%d",&n)&&n)
11     {
12         if(n%2==0)
13             printf("8600\n");
14         else
15             printf("ailyanlu\n");
16     }
17     return 0;
18 }

题意:

棋盘的尺寸是n*m。首先,把一枚硬币放在右上角(1,m)。每次一个人可以把硬币移到左边,下面或者左边下面的空格里。不能采取行动的人将会输掉比赛。

先手赢了打印出Wonderful!,输了打印另一个

题解:

打个表就可以看出来,长或者宽只要有一个为偶数,那么就必胜

 1 #include <cstdio>
 2
 3 #include <cstdlib>
 4
 5 #include <cstring>
 6
 7 #include <algorithm>
 8
 9
10
11 using namespace std;
12
13
14
15 int main(){
16     int n,m;
17
18     while(scanf("%d %d",&n,&m)!=EOF){
19
20         if(n==0 && m==0)break;
21
22         if(n%2==0 || m%2==0){
23
24             printf("Wonderful!\n");
25
26         }else{
27
28             printf("What a pity!\n");
29
30         }
31
32     }
33
34     return 0;
35
36 }

HDU 1564 Play a game && HDU 2147 kiki's game

原文地址:https://www.cnblogs.com/kongbursi-2292702937/p/11371503.html

时间: 2024-10-12 19:54:05

HDU 1564 Play a game && HDU 2147 kiki's game的相关文章

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

http://acm.hdu.edu.cn/showproblem.php?pid=2147 题意:n×m的棋盘,每次可以向左走.向下走.向左下走,初始在(1, m),n,m<=2000,问先手是否胜利. #include <cstdio> using namespace std; int main() { int n, m; while(scanf("%d%d", &n, &m), n|m) (n&1)&&(m&1)?

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