zoukankan      html  css  js  c++  java
  • LightOJ 1393 Crazy Calendar(博弈)题解

    题意:r*c方格中,每个格子有一定石子,每次移动每格任意数量石子,只能向下或者向右动一格,不能移动为败

    思路:显然是Nim,到右下曼哈顿距离为偶数的不用管,因为先手动一下后手动一下最后移到右下后还是先手的回合;奇数移动一格必到偶数格,所以奇数的Nim一下。很简单的入门题。

    代码:

    #include<set>
    #include<map>
    #include<stack>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    typedef long long ll;
    const int maxn = 5e4 + 10;
    const int seed = 131;
    const ll MOD = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    int main(){
        int T, r, c, Case = 1;
        ll n, ans;
        scanf("%d", &T);
        while(T--){
            ans = 0;
            scanf("%d%d", &r, &c);
            for(int i = 1; i <= r; i++){
                for(int j = 1; j <= c; j++){
                    scanf("%lld", &n);
                    int dis = r - i + c - j;
                    if(dis & 1) ans ^= n;
                }
            }
            if(ans) printf("Case %d: win
    ", Case++);
            else printf("Case %d: lose
    ", Case++);
        }
        return 0;
    }
  • 相关阅读:
    DP -- 递推
    二分查找题
    动态规划
    二分专题
    并查集
    三分法
    二分法
    插入排序
    排序小结
    Go go.mod入门
  • 原文地址:https://www.cnblogs.com/KirinSB/p/9706787.html
Copyright © 2011-2022 走看看