Cod sursa(job #1205363)

Utilizator andreiiiiPopa Andrei andreiiii Data 6 iulie 2014 12:20:33
Problema Bowling Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <algorithm>
#include <bitset>
#include <cstdio>

using namespace std;

int Sg[86];

inline int getval(const int x)
{
    if (x > 70) return  71 + (x - 71) % 12;
    return x;
}

int main()
{
    freopen("bowling.in", "r", stdin);
    freopen("bowling.out", "w", stdout);

    for (int i = 1; i <= 82; i++)
    {
        bitset<200> v;
        for (int j = 0; j <= i / 2; j++)
            v[Sg[j] ^ Sg[i - j - 1]] = 1;
        for (int j = 0; j <= (i - 1) / 2; j++)
            v[Sg[j] ^ Sg[i - j - 2]] = 1;

        for (int j = 0; ; j++)
        {
            if (!v[j])
            {
                Sg[i] = j;
                break;
            }
        }
    }

    int T;
    scanf("%d", &T);

    while (T--)
    {
        int N;
        scanf("%d", &N);

        int S = 0, count = 0;
        for (int i = 1; i <= N; i++)
        {
            int x;
            scanf("%d", &x);

            if (x) count++;
            else
            {
                S ^= Sg[getval(count)];
                count = 0;
            }
        }

        S ^= Sg[getval(count)];

        if (S) printf("Nargy\n");
        else printf("Fumeanu\n");
    }
}