Pagini recente » Cod sursa (job #1040998) | Cod sursa (job #1994793) | Cod sursa (job #1605401) | Cod sursa (job #2399504) | Cod sursa (job #198140)
Cod sursa(job #198140)
#include<stdio.h>
#define lmax 10010
int n,l,st[2][lmax],x;
char ca[20050];
int b[2][7]={{2,5,2},{5,6,4,3,4,1}};
int c[3][7]={{1,2},{3,6,5,3},{3,4,2,1}};
bool eok[2];
int main()
{
freopen("perle.in","r",stdin);
freopen("perle.out","w",stdout);
int i,j,k;
bool ok;
scanf("%d",&n);
for(; n; n--)
{
scanf("%d",&l);
if(l==1)
{
fgets(ca,20050,stdin);
printf("1\n");
}
else
{
eok[0]=eok[1]=true;
st[0][0]=st[1][0]=1;
st[0][1]=5;
st[1][1]=6;
while((l)&&(eok[0]||eok[1]))
{
l--;
scanf("%d",&x);
for(i=0; i<2; i++)
{
if(eok[i])
{
if(st[i][0]<1)
eok[i]=false;
else
if(st[i][st[i][0]]<4)
{
if(st[i][st[i][0]]==x)
st[i][0]--;
else
eok[i]=false;
}
else
if(st[i][st[i][0]]==4)
st[i][0]--;
else
{
if(st[i][st[i][0]]==5)
{
ok=true;
for(j=0; (j<2)&&(ok); j++)
{
if(b[j][b[j][0]]==x)
{
ok=false;
st[i][0]--;
for(k=1; k<b[j][0]; k++)
st[i][++st[i][0]]=b[j][k];
}
}
if(ok)
eok[i]=false;
}
else
{
ok=true;
for(j=0; (j<3)&&(ok); j++)
{
if(c[j][c[j][0]]==x)
{
ok=false;
st[i][0]--;
for(k=1; k<c[j][0]; k++)
st[i][++st[i][0]]=c[j][k];
}
}
if(ok)
eok[i]=false;
}
}
}
}
}
if(!l)
{
if((eok[0])&&(st[0][0]==0))
printf("1\n");
else
if((eok[1])&&(st[1][0]==0))
printf("1\n");
else
printf("0\n");
}
else
{
fgets(ca,20050,stdin);
printf("0\n");
}
}
}
return 0;
}