HDU 2147 kiki's game (奇偶博弈)

题意:给定一个 n * m 的格子,从右上角(1, m) 开始每个玩家只能从向下,向左,或者向左下走,谁不能走,谁输。

析:自己做出来,看了网上的几个博客,好像都没说为什么是只有全奇的情况才会输,个人的理解如下,如果不对,欢迎指正。

首先,从(1, m)  走到 (n, 1) 这才是一个完整的,也就是如果论到谁开始移动的时候当时的位置是 (n, 1),那么它就输了,因为只能向下,向左,向左下,而这些方向都出界了。这样看不大好看,我们可以看成是从 (n, m) 走到 (1, 1),同理如果论到谁开始移动的时候当时的位置是 (1, 1),那么它就输了,很明显这个位置(1, 1),是双奇(意思就是横纵坐标都是奇数),双奇可以变成一奇一偶(向左走或向下走),或者是变成双偶(向左下走),当然前提是还有路可走,但它怎么走也不可能变成双奇,而一奇一偶,双偶都可以变成双奇,恰恰双奇是必败态,所以只要玩家每次都给对方是双奇,那么给它的最后一定是 (1, 1),也就是给他的是必败态,自己是可保证胜态。所以只要 n 和 m 不是双奇,就可以胜。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define all 1,n,1
#define FOR(i,x,n)  for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.in", "r", stdin)
#define freopenw freopen("out.out", "w", stdout)
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 2000 + 10;
const int maxm = 100 + 2;
const LL mod = 100000000;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
  return r >= 0 && r < n && c >= 0 && c < m;
}

int main(){
  while(scanf("%d %d", &n, &m) == 2 && n+m){
    if(n&1&&m&1) puts("What a pity!");
    else  puts("Wonderful!");
  }
  return 0;
}

  

原文地址:https://www.cnblogs.com/dwtfukgv/p/8432367.html