Cod sursa(job #1222527)

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

int main(void) {
    ifstream fin("bowling.in");
    ofstream fout("bowling.out");
    
    for (i=1; i<=84; ++i) {
        memset(aux,0,sizeof(aux));
         
        for (j=1; j<=i/2+1; ++j) { 
                              aux[ sg[j-1]^sg[i-j] ]=1;
                              if (j>1) 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 {
                  if (l>84) l=72+(l-72)%12+1; 
                  
                  sum^=sg[l];
                  l=0;
                  }
             }
         
         if (l>84) l=72+(l-72)%12+1;
          
         sum^=sg[l];
         
         if (sum>0) fout<<"Nargy\n";
         else fout<<"Fumeanu\n";   
     
         }   

    return 0;
}