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

题目描述

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?

思路

组合博弈部分,先考虑m和n都为奇数的时候,比如3x3,易知先手必输。然后分别考虑m,n取值为偶奇、偶偶、奇偶的时候,易知必胜。

AC代码

/*************************************************************************
    > File Name: 2147.cpp
      > Author: Netcan
      > Blog: http://www.netcan.xyz
      > Mail: 1469709759@qq.com
      > Created Time: 2015-07-21 Tue 10:15:03 CST
 ************************************************************************/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <sstream>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <stack>
#include <set>
#include <numeric>
#include <utility>
#include <cstring>
using namespace std;
int main()
{
#ifdef Oj
    // freopen(".in", "r", stdin);
#endif
    int n, m;
    while(cin >> n >> m) {
        if(n == 0 && m ==0)
            break;
        if(m&1) {
            if(n&1) // 都为奇的时候必输。
                puts("What a pity!");
            else
                puts("Wonderful!");
        }
        else
            puts("Wonderful!");
    }
    return 0;
}