题意:n*m的方格,走过的格子不能走,一开始在角落上,可以斜着走,最后无路可走就算输,求最后谁赢。
题解:博弈+规律
画PN状态图。
步骤1:将所有终结位置标记为必败点(P点);
步骤2: 将所有一步操作能进入必败点(P点)的位置标记为必胜点(N点)
步骤3:如果从某个点开始的所有一步操作都只能进入必胜点(N点) ,则将该点标记为必败点(P点) ;
步骤4: 如果在步骤3未能找到新的必败(P点),则算法终止;否则,返回到步骤2。
最后结果为:
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
可以发现行或列为偶数,先手必胜。
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<fstream>
#include<set>
#include<map>
#include<sstream>
#include<iomanip>
#define ll long long
using namespace std;
int n, m;
int main() {
while (scanf("%d%d", &n, &m) && n) {
int x = n * m;
if (x & 1) puts("What a pity!");
else puts("Wonderful!");
}
return 0;
}