Pagini recente » Cod sursa (job #1502970) | Cod sursa (job #3230368) | Cod sursa (job #787927) | Cod sursa (job #1663401) | Cod sursa (job #529822)
Cod sursa(job #529822)
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( 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;
}