hdu 2147博弈找规律

http://acm.hdu.edu.cn/showproblem.php?pid=2147

分析:我看测试数据就觉得n*m是奇数和偶数的时候进行分类就行了。没证明。

网上分析:http://www.cnblogs.com/chaosheng/archive/2012/05/29/2524725.html

P点:就是P个石子的时候,对方拿可以赢(自己输的)

N点:就是N个石子的时候,自己拿可以赢

现在关于P,N的求解有三个规则

(1):最终态都是P

(2):按照游戏规则,到达当前态的前态都是N的话,当前态是P

(3):按照游戏规则,到达当前态的前态至少有一个P的话,当前态是N

题意:

在一个m*n的棋盘内,从(1,m)点出发,每次可以进行的移动是:左移一,下移一,左下移一。然后kiki每次先走,判断kiki时候会赢(对方无路可走的时候)。

我们可以把PN状态的点描绘出来::

hdu-2147:kikis game - 陈年往事 - 我学acm 的博客

View Code
// I'm lanjiangzhou
//C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
//C++
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cctype>
#include <stack>
#include <string>
#include <list>
#include <queue>
#include <map>
#include <vector>
#include <deque>
#include <set>
using namespace std;

//*************************OUTPUT*************************
#ifdef WIN32
#define INT64 "%I64d"
#define UINT64 "%I64u"
#else
#define INT64 "%lld"
#define UINT64 "%llu"
#endif

//**************************CONSTANT***********************
#define INF 0x3f3f3f3f

// aply for the memory of the stack
//#pragma comment (linker, "/STACK:1024000000,1024000000")
//end



int main(){
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF){
        if(n==0&&m==0) break;
        if(n*m%2==0) printf("Wonderful!\n");
        else printf("What a pity!\n");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/lanjiangzhou/p/3019319.html