Cod sursa(job #270589)

Utilizator raduzerRadu Zernoveanu raduzer Data 4 martie 2009 11:10:50
Problema Bowling Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAX_N = 1000;

int n, z, t;
int f[MAX_N];
int sg[MAX_N];

int main()
{
	int i, j;
	freopen("bowling.in", "r", stdin);
	freopen("bowling.out", "w", stdout);
	
	f[0] = -1;
	for (i = 1; i <= 100; ++i)
	{
		z = 0;
		for (j = 0; j < i - 1; ++j)
			f[++z] = sg[j] ^ sg[i - j - 2];
		
		for (j = 0; j < i; ++j)
			f[++z] = sg[j] ^ sg[i - j - 1];
		
		sort(f + 1, f + z + 1);
		f[z + 1] = f[z] + 10;
		
		for (j = 0; j <= z; ++j)
			if (f[j] + 1 < f[j + 1])
			{
				sg[i] = f[j] + 1;
				break;
			}
	}
	
	for (scanf("%d", &t); t; --t)
	{
		int y = 0, x, rez = 0;
		for (scanf("%d", &n); n; --n)
		{
			scanf("%d", &x);
			
			if (x) 
			{
				++y;
				continue;
			}
			
			if (y < 72) rez ^= sg[y];
			else rez ^= sg[(y - 71) % 12 + 72 + (!(y - 71) % 12) ? 11 : 0];
		}
		
		printf("%s\n", (rez) ? "Nargy" : "Fumeanu");
	}
}