light oj 1393 - Crazy Calendar 博弈论

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

只需考虑与右下角奇偶不同的位置,可以看成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\n",++ca,ans?"win":"lose");
21     }
22     return 0;
23 }
View Code

 

 

 

posted @ 2013-10-02 18:28  _随心所欲_  阅读(282)  评论(0编辑  收藏  举报