HDU 2147 kiki's game
阿新 • • 發佈:2018-01-30
pac fec 棋盤 每次 contains ace sample rst include 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 }
HDU 2147 kiki's game