版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37753409/article/details/82758114
LightOJ-1253 Misere Nim
nim博弈的变形。
和一般nim博弈的区别:最后一个取石子的lose,输出win的人。
还是亦或求解, 只要特判全是1的情况。
#include <bits/stdc++.h>
using namespace std;
int main () {
int t, n, kase = 0, x;
cin >> t;
while (t--) {
cin >> n;
cin >> x;
int status = x;
int flag = 0;
if (x != 1) flag = 1;
for (int i = 1; i < n; i++) {
cin >> x;
status ^= x;
if (x != 1) flag = 1;
}
if (flag)
cout << "Case " << ++kase << ": " << (!status ? "Bob" : "Alice") << "\n";
else
cout << "Case " << ++kase << ": " << (n % 2 ? "Bob" : "Alice") << "\n";
}
return 0;
}