kiki’s game

C - kiki’s game

题目

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?

题意

kiki和ZZ玩游戏,有一个n*m的矩阵,在右上角(1,m)的位置放置着一枚硬币,两个人轮流移动硬币,硬币可以往左边,下边以及左下方移动,每次移动一个空位,最终不能移动硬币的人输掉比赛,如果kiki和ZZ都采用最优的策略,那么请问谁将会赢得比赛?

类型

巴什博弈

分析

可以用1表示必胜点,0表示必败点,那么可以写出这样的矩阵(n=4,m=4):

1  1  1  1   
0  1  0  1 
1  1  1  1
0  1  0  1

由此可得 构造矩阵map[2][2],并且map[2][2]={1,1,1,0}(因为当n=1,m=1时,局势为必败状态,那么map[1][1]=0,其余的2*2的矩阵中的局势均为必胜局势,所以全部为1)。

代码

#include<stdio.h>
int map[2][2] = {1,1,1,0};
int main()
{
int n, m;
while(scanf("%d%d", &n, &m)&&n&&m)
{
    n = n % 2;
    m = m % 2;
    if( map[n][m] == 1) printf("Wonderful!\n");
    else
        printf("What a pity!\n");
}
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值