c++ Nim取子游戏 博弈论

Problem description:
There are N heaps of coins on the table ordered in a row. In the i-th heap there are exactly ai coins.
Additionally, it is known that ai ≤ aj if i < j.
Alice and Bob play a game with these coins. At each move it is allowed to take any positive amount of coins from any heap, but the condition (ai ≤ aj if i < j) must remain satisfied. The player who takes the last coin, wins.
You should find who wins if no one makes a mistake and Bob gets to make the first move.

Input
The input consists of
• one line containing N (1 ≤ N ≤ 10^5) – the number of heaps
• one line containing N numbers a1, a2, ..., aN (1 ≤ ai ≤ 10^9) – the sizes of the heaps.

Output
If Bob wins output “Bob", otherwise output “Alice".

InputOutput
1Bob
10-
------------
2Alice
10 10-
------------
2Bob
10 15-

另有一组较大的测试数据,600个不同的数字

根据题意我提交的代码如下,虽然测试数据都是对的,但是并没有通过,希望大家可以帮忙看下哪里出了问题呢?

#include <iostream>
#include <algorithm>
using namespace std;

const int N = 100010;

/*
Lose First :a1 ^ a2 ^ a3 ^ ... ^an = 0
Win First:a1 ^ a2 ^ a3 ^ ... ^an ≠ 0
*/

int main()
{

    int n;
    cin >> n;

    int res = 0;
    while (n--)
    {

        int a;
        cin >> a;
        res ^= a;
    }

    if (res) puts("Bob");
    else puts("Alice");

    return 0;
}

应该是没有问题的。

#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100010;
/*
Lose First :a1 ^ a2 ^ a3 ^ ... ^an = 0
Win First:a1 ^ a2 ^ a3 ^ ... ^an ≠ 0
*/
int main()
{
    int n;
    cin >> n;
    int res = 0;
    while (n--)
    {
        int a;
        cin >> a;
        res ^= a;
    }
    if (res) puts("Bob");
    else puts("Alice");
    return 0;
}

img


#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
 
 
scanf("%d",&n);
 
if(n%(3+1)==0)
 
printf("falsee\n");
 
else
 
printf("true\n");
 
 
 
return 0;
 
}

算法没看出有什么问题,题目可能要求你的程序对多组测试数据输出结果

#include <iostream>

using namespace std;

/*
Lose First :a1 ^ a2 ^ a3 ^ ... ^an = 0
Win First:a1 ^ a2 ^ a3 ^ ... ^an ≠ 0
*/

int main()
{
    int n;
    while (cin >> n)
    {
        int res = 0;
        while (n--)
        {
            int a;
            cin >> a;
            res ^= a;
        }
        if (res)
            puts("Bob");
        else
            puts("Alice");
    }
    return 0;
}