链接:
https://codeforces.com/problemset/problem/1527/B1
题意:
Alice和Bob玩游戏,给一个回文数(只含有0和1),Alice先动,Bob后动,他们可以对其进行以下两种操作,把任意位置上的0改成1,消耗1d,或将整个字符串倒转,如01001变成10010,但只有字符串不是回文数时,可以这样操作,并且不能连续对字符串进行这个操作,消耗0d。最后使字符串全变成1后,游戏结束,谁消耗少谁赢。
本题只有0的数量是奇数并且数量大于1时,Alice赢。
代码如下:
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<random>
using namespace std;
typedef long long ll;
int main() {
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
string s;
cin >> s;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
cnt++;
}
}
if ((cnt & 1)&& cnt>1) {
cout << "ALICE";
}
else {
cout << "BOB";
}
cout << endl;
}
return 0;
}