Cod sursa(job #522009)

Utilizator APOCALYPTODragos APOCALYPTO Data 13 ianuarie 2011 23:38:38
Problema Perle Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
using namespace std;

#include<iostream>
#include<fstream>
ofstream fout("perle.out");
int N,a[10001];
int tc(int poz);
int tb(int poz)
{
    if(poz>N-4) return 0;
    //if(poz==N-4 &&a[poz]==1&&a[poz+2]==3 &&a[poz+4]==2) return poz+4;
    if(a[poz]==2)
        return tb(poz+1);
    if(a[poz]==1 && a[poz+2]==3)
        return tc(poz+4);
    return 0;
}

int tc(int poz)
{
    if(poz>N) return 0;
    if(poz==N && a[poz]==2) return poz;
    if(poz<=N-2&& a[poz]==1 &&a[poz+1]==2 ) return poz+2;
    if(a[poz]==3)
    {
      int index=tb(poz+1);
      if(index!=0&&index<N)
        return tc(index+1);
    }
    return 0;
}

int test()
{
    if(N==1) return 1;
    if(tb(1)==N || tc(1)==N) return 1;
    return 0;
}

void cit()
{
    ifstream fin("perle.in");
    int T,i;
    fin>>T;

    while(T--)
    {
        fin>>N;
        for(i=1;i<=N;i++)
        {
            fin>>a[i];
        }

        fout<<test()<<"\n";
    }


    fin.close();

}

int main()
{
    cit();
    fout.close();
    return 0;
}