Codeforces Round #721 (Div. 2)

B1. Palindrome Game (easy version)
博弈,如果有偶数个0,A选完后,B选对称的,A就只能再选。直到最后剩2个,此时A选完后,B翻转。
如果有奇数个0,A首先选中间的0,然后情况类似。

代码

 char s[N];
 2 int main()
 3 {
 4     ios::sync_with_stdio(false); cin.tie(nullptr);
 5  
 6     int t;
 7     cin >> t;
 8     while (t--) {
 9         int n;
10         cin >> n;
11         int sum = 0;
12  
13         for (int i = 1; i <= n; i++) {
14             cin >> s[i];
15             if (s[i] == '0')
16                 sum++;
17         }
18         if (sum == 1) {
19             cout << "BOB" << endl;
20             continue;
21         }
22         if (sum % 2) {
23             cout << "ALICE";
24         }
25         else
26             cout << "BOB";
27         cout << endl;
28     }
29 }
  
原文地址:https://www.cnblogs.com/lingshi321/p/14810601.html