LightOJ-1247 Matrix Game

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37753409/article/details/82758015

LightOJ-1247 Matrix Game

每一行n个的石头块的数量之和为一堆,共m堆, 转化成普通nim博弈, 亦或求解。


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100;

int main () {
    int t, n, m, x;
    int kase = 0;
    cin >> t;
    while (t--) {
        cin >> m >> n;
        int p = 0;
        
        for (int j = 0; j < n; j++) {
            cin >> x;
            p += x;
        }
        int status = p;
        for (int i = 1; i < m; i++) {
            p = 0;
            for (int j = 0; j < n; j++) {
                cin >> x;
                p += x;
            }
            status ^= p;
        }
        cout << "Case " << ++kase << ": " << (status == 0 ? "Bob" : "Alice") << "\n";
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37753409/article/details/82758015
今日推荐