题解 P4702 【取石子】

· · 题解

这题可以采用异或的思想。

之前做过类似的问题求解。

这样做能保证答案正确。

类似的题目都可以使用。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int x=0;
    cin >> n;
    for (int i=1; i<=n; i++)
    {
         int y;
         cin >> y;//输入
         x^=y;//异或
    }
    if (x%2==1) cout << "Alice";
    else cout << "Bob";//输出
}