kiki's game

来源:互联网 发布:湖北航天信息开票软件 编辑:程序博客网 时间:2024/05/02 05:02

2010-01-16 00:03:58|  分类: 博弈|举报|字号 订阅

下载LOFTER客户端

Problem 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). <="" div="" m="0." and="" n="0" when="" terminated="" is="" input="" the="">

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!

Author
月野兔

Source
HDU 2007-11 Programming Contest

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 的博客

这些点的描绘有一个程序::

#include<iostream>
using namespace std;
bool map[2001][2001];//1 P 0 N;
int main(){
       int i,j,k;
       map[1][1]=1;
       for(i=2;i<=2000;i++)
       {
              if(map[i-1][1])
                     map[i][1]=0;
              else map[i][1]=1;
              for(j=2;j<i;j++){
                     if(!map[i][j-1]&&!map[i-1][j-1]&&!map[i-1][j])
                            map[i][j]=1;
                     else map[i][j]=0;
              }
              if(map[1][i-1])
                     map[1][i]=0;
              else map[1][i]=1;
              for(j=2;j<i;j++){
                     if(!map[j-1][i]&&!map[j-1][i-1]&&!map[j][i-1])
                            map[j][i]=1;
                     else map[j][i]=0;
              }
              if(!map[i][i-1]&&!map[i-1][i-1]&&!map[i-1][i])
                     map[i][i]=1;
              else map[i][i]=0;
       }
       int M,N;
       for(i=1;i<=10;i++){
              for(j=1;j<=10;j++)
                     printf("%c ",map[i][j]?'P':'N');
              printf("\n");
       }
       while(scanf("%d%d",&M,&N)&&M&&N){
              if(map[M][N]) printf("What a pity!\n");
              else printf("Wonderful!\n");
       }
       return 0;
}

具体代码::

#include <iostream>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b&&a&&b)
    {
        a%=2;
        b%=2;
        if(a&&b)cout<<"What a pity!"<<endl;
        else cout<<"Wonderful!"<<endl;
    }
}

0 0