Cod sursa(job #1222500)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 23 august 2014 14:13:51
Problema Bowling Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include<fstream>
#include<cstring>
using namespace std;
int i,j,n,sg[1000],t;
bool aux[10];

int main(void) {
    ifstream fin("bowling.in");
    ofstream fout("bowling.out");
    
    for (i=1; i<=500; ++i) {
        memset(aux,0,sizeof(aux));
        //bat cite 1
        for (j=1; j<=i/2+1; ++j) aux[ sg[j-1]^sg[i-j] ]=1;
        //bat cite 2
        for (j=2; j<=i/2+1; ++j) aux[ sg[j-2]^sg[i-j] ]=1;
        
        while (aux[ sg[i] ]) ++sg[i];
        
        }   
     
     fin>>t;
     
     for (; t>0; --t) {
         fin>>n;
         int l=0,sum=0;
         
         for (i=1; i<=n; ++i){
             int x;
             fin>>x;
             if (x==1) ++l;
             else {
                  sum^=sg[l];
                  l=0;
                  }
             }
          
         sum^=sg[l];
         
         if (sum>0) fout<<"Nargy\n";
         else fout<<"Fumeanu\n";   
     
         }   
    
    
    return 0;
}