Cod sursa(job #1729436)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 14 iulie 2016 18:29:58
Problema Bowling Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <bitset>

using namespace std;

ifstream fin("bowling.in");
ofstream fout("bowling.out");

const int dim = 101;

int sg[dim];
void precalcSG100(void) {

	static bitset<dim + dim> used;
	sg[0] = 0, sg[1] = 1, sg[2] = 2;

	for (int i = 3; i <= 100; ++i) {

		used.reset();

		for (int j = 0; j < i; ++j)
			used[sg[j] ^ sg[i - 1 - j]] = true;

		for (int j = 0; j < i - 1; ++j)
			used[sg[j] ^ sg[i - 2 - j]] = true;

		for (int j = 0; j <= 200; ++j)
			if (!used[i]) { sg[i] = j; break; }

	}

}

inline int getSg(int x) {

	return (x <= 80 ? sg[x] :sg[ 80 + (x - 80) % 12 ]);

}

int main() {

	int testCount;
	fin >> testCount;

	precalcSG100();

	for (; testCount; --testCount) {

		int n; fin >> n;

		int cur = 0, ans = 0;
		for (int i = 1; i <= n; ++i) {

			int x; fin >> x;

			if (x == 1)
				++cur;
			else {
				ans ^= getSg(cur);
				cur = 0;
			}

		}

		ans ^= getSg(cur);
		fout << (ans ? "Nargy\n" : "Fumeanu\n");

	}

	return 0;

}

//Trust me, I'm the Doctor!