Cod sursa(job #1797611)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 4 noiembrie 2016 17:45:44
Problema Bowling Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.83 kb
#include <fstream>

using namespace std;

ofstream fout ("bowling.out");

class InputReader {
	public:
        InputReader() {}
        InputReader(const char *name) {
            fin = fopen(name, "r");
			buffpos = Size - 1;
        }
        inline InputReader &operator >>(int &n) {
			char ch = nextpos();
            while(ch < '0' || ch > '9') {
                ch = nextpos();
            }
            n = 0;
            while('0' <= ch && ch <= '9') {
                n = n * 10 + ch - '0';
                ch = nextpos();
            }
            return *this;
        }
    private:
        FILE *fin;
        static const int Size = 1 << 17;
        int buffpos;
        char buff[Size];

        inline char nextpos() {
            ++ buffpos;
            if(buffpos == Size) {
                buffpos = 0;
                fread(buff, Size, 1, fin);
            }
			return buff[ buffpos ];
        }
} fin ("bowling.in");

const int nmax = 100;

bool viz[nmax + 1], f[2 * nmax + 1];
int v[nmax + 1];

void dfs (int nod) {
    viz[ nod ] = 1;

    for (int i = 0; i <= nod; ++ i) {
        if (viz[ i ] == 0) dfs( i );
        if (viz[nod - i - 1] == 0) dfs(nod - i - 1);
        if (nod - i - 2 >= 0 && viz[nod - i - 2] == 0) dfs(nod - i - 2);
    }

    for (int i = 0; i <= nod; ++ i) {
        f[ v[ i ] ^ v[nod - i - 1] ] = 1;
        if (nod - i - 2 >= 0) {
            f[ v[ i ] ^ v[nod - i - 2] ] = 1;
        }
    }

    for (int i = 0; ; ++ i) {
        if (f[ i ] == 0) {
            v[ nod ] = i; break;
        }
    }

    for (int i = 0; i <= nod; ++ i) {
        f[ v[ i ] ^ v[nod - i - 1] ] = 0;
        if (nod - i - 2 >= 0) {
            f[ v[ i ] ^ v[nod - i - 2] ] = 0;
        }
    }
}

inline int val (int x) {
    if (x < nmax) return v[ x ];
    x = (x - nmax) % 12;

    switch( x ) {
        case 0: return 1;
        case 1: return 4;
        case 2: return 7;
        case 3: return 2;
        case 4: return 1;
        case 5: return 8;
        case 6: return 2;
        case 7: return 7;
        case 8: return 4;
        case 9: return 1;
        case 10: return 2;
        default: return 8;
    }
}

int main() {
    viz[ 0 ] = 1;
    for (int i = 1; i < nmax; ++ i) {
        if (viz[ i ] == 0) {
            dfs( i );
        }
    }

    int t;
    fin >> t;

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

        int ans = 0;
        int last = 1;
        for (int i = 1; i <= n; ++ i) {
            int x;
            fin >> x;

            if (x == 0) {
                if (last < i) {
                    ans ^= val(i - last);
                }
                last = i + 1;
            }
        }

        if (last <= n) {
            ans ^= val(n - last + 1);
        }

        if (ans == 0) {
            fout << "Fumeanu\n";
        } else {
            fout << "Nargy\n";
        }
    }

    fout.close();
    return 0;
}