题目
思路
说一个很重要的性质:每一行的棋子的具体位置并不重要,重要的是二者之间的距离。
为什么呢?因为必胜的一方可以 认为 你的棋子无法后退。利用下方的对抗性策略:
- 如果你的棋子后退 x x x 步,则它的棋子前进 x x x 步,仍然保持原有距离。
- 如果你的棋子前进,则按照必胜策略进行。
求解必胜策略时,假装你的所有棋子都在边界。很明显,这是可以做到必胜的。
但是,我们用归纳的思想去思考,就会发现:在必胜策略中,你不得不将棋子向前移动(因为我们假设你的所有棋子都在边界),然后又变成了“棋子不在边界”的情况,可以再次转化成“棋子在边界”的情况!
所以,现在问题就变成了:有 n n n 个数(表示距离),每个操作者都可以任选其中一个,使其减少,但不可以减少至负数,也不可以不减少。不能操作者输。
变成 nim \text{nim} nim 游戏了耶!有意思!
代码
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
inline int readint(){
int a = 0; char c = getchar(), f = 1;
for(; c<'0' or c>'9'; c=getchar())
if(c == '-') f = -f;
for(; '0'<=c and c<='9'; c=getchar())
a = (a<<3)+(a<<1)+(c^48);
return a*f;
}
inline void writeint(long long x){
if(x < 0) putchar('-'), x = -x;
if(x > 9) writeint(x/10);
putchar((x%10)^48);
}
# define MB template < class T >
MB void getMax(T &a,const T &b){ if(a < b) a = b; }
MB void getMin(T &a,const T &b){ if(b < a) a = b; }
int main(){
int n, res;
while(scanf("%d %*d",&n) != -1){
res = 0;
for(int i=1; i<=n; ++i)
res ^= abs(readint()-readint())-1;
puts(res == 0 ? "BAD LUCK!" : "I WIN!");
}
return 0;
}