Lightoj1393(博弈+NIM)

来源:互联网 发布:数据分析报表怎么做 编辑:程序博客网 时间:2024/06/05 05:41

题意:给出一个矩阵,每个点都有一些石子,有两个人移石子,只能向右移或向下移,直到谁不能移谁输。

分析:在和最后一个点奇偶性相同的点移偶数次就能到,所以可以不考虑,剩下的就是一个简单的NIM博弈。

代码如下:

#include <math.h>#include <vector>#include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>using namespace std;int main(){    int t;    scanf("%d",&t);    int k=1;    while(t--){        int n,m,x;        scanf("%d%d",&n,&m);        int sum=0;        for(int i=1;i<=n;i++){            for(int j=1;j<=m;j++){                scanf("%d",&x);                if(((i+j)%2)!=((m+n)%2))                sum^=x;            }        }        if(sum==0)printf("Case %d: lose\n",k++);        else printf("Case %d: win\n",k++);    }    return 0;}


0 0