HDU 2147 kiki's game(博弈)

本文解析了一款名为Kiki's Game的策略游戏,玩家在N*M的棋盘上移动硬币,目标是迫使对手无法移动。文章给出了获胜条件:若N和M均为奇数,则初始玩家必败;否则必胜。并提供了简洁的C++实现代码。
Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u

 Status

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!
 
题意:有一个N*M的棋盘,硬币在(1,M),两个人轮流移动,每次可以将硬币向左或向下或向左下移动。
   谁不能继续移动了谁输,赢了输出Wonderful!,输了输出What a pity!。
题解:左下角肯定是必败点P了,他的上,右和右上是必胜点N,依次递推可以得出:
   PNPNPNPNP
   NNNNNNNNN
   PNPNPNPNP
   NNNNNNNNN
   PNPNPNPNP
   NNNNNNNNN
   PNPNPNPNP
   即如果n和m都是奇数则为必败点,否则为必胜点。
注意:本题也叫“分”数问题,给定两个数每次将一个数变为0,另一个数分成两份给这两个数。
   结论与本题一样,都是奇数则必败,根据(1,1)是P然后逆向递推即可得出结论。
   顺便说一下另一种博弈:Chomp!博弈,即拿巧克力问题。结论:除了(1,1)都是必胜点。很好证明:
   如果后手能赢,也就是说后手有必胜策略,使得无论先手第一次取哪个石子,后手都能获得最后的胜利。
   那么现在假设先手取最右上角的石子(n,m),接下来后手通过某种取法使得自己进入必胜的局面。
   但事实上,先手在第一次取的时候就可以和后手这次取的一样,进入必胜局面了,与假设矛盾。
以下是本题AC代码:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,m;
    while(cin>>n>>m&&n&&m)
    {
        if(n&1&&m&1) puts("What a pity!");
        else puts("Wonderful!");
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/Ritchie/p/5626496.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值