HDU 2147 kiki's game

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). 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!
这东西好像叫巴什博弈
跟上一题一样,最后(n,m)肯定是P
然后一个一个推出(1,1)是N还是P
但是每次都2000×2000可能会超
所以把棋盘反转(n,m)变成了(1,1)
于是直接判断(1,1)~(n,m)
起点就变成了(n,m),终点为(1,1)可以O(1)查询
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 bool ans[2001][2001];
 8 int n,m;
 9 int main()
10 {int i,j;
11   ans[1][1]=0;
12   for (i=2;i<=2000;i++)
13     if (ans[1][i-1]==1)
14       ans[1][i]=0;
15     else ans[1][i]=1;
16   for (i=2;i<=2000;i++)
17     if (ans[i-1][1]==1)
18       ans[i][1]=0;
19     else ans[i][1]=1;
20   for (i=2;i<=2000;i++)
21     {
22       for (j=2;j<=2000;j++)
23     {
24       if (ans[i-1][j]==0||ans[i][j-1]==0||ans[i-1][j-1]==0)
25         ans[i][j]=1;
26       else ans[i][j]=0;
27     }
28     }
29   while (cin>>n>>m&&n&&m)
30     {
31       if (ans[n][m]==1)
32     printf("Wonderful!\n");
33       else printf("What a pity!\n");
34     }
35 }

 

posted @ 2018-01-30 20:52  Z-Y-Y-S  阅读(174)  评论(0编辑  收藏  举报