杭电ACM2147——kiki' game

Problem Description: 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?
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! 
题目分析:其实这是一个NP完全问题,额....需要画表格分析。画表格好辛苦的说~~~
N表示先手胜,P表示后手胜。
1:可以移到P点的局面都是N。
2:所有移动都导致N的是P。
P N P N P N P
N N N N N N N
P N P N P N P
N N N N N N N
P N P N P N P
N N N N N N N
P N P N P N P
ok,细心的你可能发现了,只要行列坐标同时为偶数,则先手不可能赢,反之先手赢。
#include<stdio.h>
void main()
{
    int n,m;
    while(scanf("%d %d", &n, &m))
    {
        if(!m && !n)
        {
            break;
        }

        if( (n & 1) && (m & 1))
        {
            printf("What a pity!\n");
        }
        else
        {
            printf("Wonderful!\n");
        }

    }
}

你可能感兴趣的:(杭电ACM2147——kiki' game)