Cod sursa(job #1741868)

Utilizator fanache99Constantin-Buliga Stefan fanache99 Data 15 august 2016 12:54:19
Problema Bowling Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <fstream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <set>
#include <map>
#include <stack>
using namespace std;

ifstream cin("bowling.in");
ofstream cout("bowling.out");


const int SG[] = {0, 1, 2, 3, 1, 4, 3, 2, 1, 4, 2, 6,
                  4, 1, 2, 7, 1, 4, 3, 2, 1, 4, 6, 7,
                  4, 1, 2, 8, 5, 4, 7, 2, 1, 8, 6, 7,
                  4, 1, 2, 3, 1, 4, 7, 2, 1, 8, 2, 7,
                  4, 1, 2, 8, 1, 4, 7, 2, 1, 4, 2, 7,
                  4, 1, 2, 8, 1, 4, 7, 2, 1, 8, 6, 7,
                  4, 1, 2, 8, 1, 4, 7, 2, 1, 8, 2, 7};

int SpragueGrundy(int x) {
    if (x < 72)
        return SG[x];
    return SG[x % 12 + 72];
}

int main() {
    int tests;
    cin >> tests;
    for (int test = 1; test <= tests; test++) {
        int n;
        cin >> n;
        int l = 0, answer = 0;
        for (int i = 1; i <= n; i++) {
            int x;
            cin >> x;
            if (x)
                l++;
            else {
                answer ^= SpragueGrundy(l);
                l = 0;
            }
        }
        answer ^= SpragueGrundy(l);
        if (answer)
            cout << "Nargy\n";
        else
            cout << "Fumeanu\n";
    }
    return 0;
}