Pagini recente » Cod sursa (job #2671964) | Cod sursa (job #2161990) | Cod sursa (job #1338270) | Cod sursa (job #1220781) | Cod sursa (job #54612)
Cod sursa(job #54612)
/* Ivan Nicolae - Bucuresti */
#include <stdio.h>
#include <string.h>
#define NMAX 10001
#define _fin "perle.in"
#define _fout "perle.out"
int i,n,t,A[NMAX+10];
int estec(int);
int esteb(int x)
{
if (x>n)
return 0;
else
if (A[x]==2)
return esteb(x+1);
else
if (A[x]==1 && A[x+2]==3)
return estec(x+4);
return 0;
}
int estec(int x)
{
if (x>n)
return 0;
else
if (A[x]==2)
return x+1;
else
if (A[x]==3)
{
int ala=esteb(x+1);
if (ala > 0)
return estec(ala);
}
else
if (A[x]==1 && A[x+1]==2)
return x+3;
return 0;
}
int main()
{
freopen(_fin,"r",stdin);
freopen(_fout,"w",stdout);
scanf("%d",&t);
for (int te=1;te<=t;te++)
{
scanf("%d",&n);
for (i=1;i<=n;i++)
scanf("%d",&A[i]);
if (esteb(1)>=n) printf("1\n");
else
if (estec(1)>=n) printf("1\n");
else
if (n == 1) printf("1\n");
else
printf("0\n");
}
fclose(stdin);
fclose(stdout);
return 0;
}