LightOJ 1253 Solution

Misere Nim : Solution

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int t, k = 1;
    cin >> t;

    while(t--)
    {
        int n;
        cin >> n;

        ll a[n], xor_sum = 0, one = 0;

        for(int i=0; i<n; i++)
        {
            cin >> a[i];

            if(a[i] == 1)
                one++;

            xor_sum ^= a[i];
        }

        if(n == one && n%2 == 0)
            cout << "Case " << k++ << ": Alice" << "\n";

        else if(n == one && n%2 == 1)
            cout << "Case " << k++ << ": Bob" << "\n";

        else if(xor_sum > 0)
            cout << "Case " << k++ << ": Alice" << "\n";

        else
            cout << "Case " << k++ << ": Bob" << "\n";
    }

    return 0;
}

Comments