light oj 1393

思路:当移到右下角时,就不能移动了。所以与右下角的奇偶性相同的位置,都不能直接到达,先手必败!

只需考虑与右下角奇偶不同的位置,可以看成NIM博弈。最后NIM和不为0的胜,否者败!!

代码如下:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #define M 105
 5 using namespace std;
 6 int main()
 7 {
 8     int t,ca=0,n,m,a;
 9     scanf("%d",&t);
10     while(t--){
11         scanf("%d%d",&n,&m);
12         int ans=0;
13         bool b=(n+m)&1;
14         for(int i=1;i<=n;i++)
15         for(int j=1;j<=m;j++){
16             scanf("%d",&a);
17             if(((i+j)&1)!=b)
18                 ans^=a;
19         }
20         printf("Case %d: %s
",++ca,ans?"win":"lose");
21     }
22     return 0;
23 }
View Code
原文地址:https://www.cnblogs.com/xin-hua/p/3349545.html