kiki's game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/10000 K (Java/Others)Total Submission(s): 12405 Accepted Submission(s): 7537
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!
这个提交会超时,可以用于找规律,发现只要m,n有一个为偶数,则先手必胜
P表示必败,N表示必胜(对于当前走的而言)
#include<bits/stdc++.h>
using namespace std;
const int N = 2000+5;
bool sg[N][N];
int n,m;
int dir[3][2] = {{1,0},{0,-1},{1,-1}};
bool check(int x, int y){//判断是否越界
if(x>0 && x<=n && y>0 && y<=m)
return true;
else
return false;
}
int main()
{
/*
首先以先手姿态考虑
*/
int i,j;
while(scanf("%d%d",&n,&m) == 2 && n != 0 && m != 0){
sg[n][1] = false;
memset(sg,false,sizeof(sg));
for(i = n; i >= 1; --i){
for(j = 1; j <= m; ++j){
bool flag = true;
if(i == n && j == 1) continue;
for(int k = 0; k < 3; ++k){//向三个方向走
int nx = i + dir[k][0];
int ny = j + dir[k][1];
if(!check(nx,ny)) continue;
if(!sg[nx][ny]){
flag = false;
break;
}
}
if(!flag){
sg[i][j] = true;
}
else
sg[i][j] = false;
}
}
for(i = 1; i <= n; ++i){
for(j = 1; j <= m; ++j){
if(sg[i][j]){
printf("N ");
}
else{
printf("P ");
}
}
printf("\n");
}
// if(sg[1][m]){
// printf("Wonderful!\n");
// }
// else{
// printf("What a pity!\n");
// }
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
while(scanf("%d%d",&n,&m) == 2 && m+n){
if(m%2 == 0 || n %2 == 0){
printf("Wonderful!\n");
}
else{
printf("What a pity!\n");
}
}
return 0;
}