Pagini recente » Cod sursa (job #2837621) | Cod sursa (job #782817) | Cod sursa (job #155387) | Cod sursa (job #722099) | Cod sursa (job #253685)
Cod sursa(job #253685)
#include<stdio.h>
#include<vector>
#include<ctime>
#include<cstdlib>
#define NMAX 5
using namespace std;
vector < int > R1[NMAX];
vector < int > R2[NMAX];
int L1[NMAX],L2[NMAX];
int L3[NMAX],L4[NMAX];
char A[1024];
int C[NMAX];
int N,T;
bool solve()
{
bool ok;
int i,j,k,a1,a2,a3;
for(i=1; i<=N; ++i)
{
scanf("%d",&C[i]);
L3[i]=L1[i];
L4[i]=L2[i];
}
vector< int >::iterator it;
for(i=1; i<=N; ++i)
{
a1=L3[i];
a2=L4[i];
a3=C[i];
if( L3[ 1 ]!=0 )
{
if( i==1 && N!=1 )
{
for( it=R1[a3].begin(); it!=R1[a3].end(); ++it )
if( C[N]==*it )
{
--L3[a3],--L3[*it];
break;
}
}
}
for(j=i+1; j<=N; ++j)
{
if( L4[a3]!=0 )// '>'
{
ok=1;
for( it=R2[a3].begin(); it!=R2[a3].end(); ++it )
if( C[j] == *it )
{
--L4[a3];ok=0;
break;
}
if( ok )
return 0;
}
else
if( L3[a3]!=0 )// '#'
{
ok=1;
for( it=R1[a3].begin(); it!=R1[a3].end(); ++it )
if( C[j] == *it )
{
--L3[a3];--L3[*it];ok=0;
break;
}
if( ok )
return 0;
}
else
break;
}
}
return 1;
}
int main()
{
freopen("episoade.in","r",stdin);
freopen("episoade.out","w",stdout);
srand( time(NULL) );
fgets( A, sizeof( A ), stdin );
int i;
int a1,nrc,sign,a2,pos;
bool q=0;
for(i=0; A[i]!=NULL && A[i]!='\n'; ++i)
{
a1=A[i];
if( a1>='1' && a1<='9' )
{
nrc=a1-'0';
sign=A[i+1];
pos=i;
if( A[pos+2]!='(' )
{
a2=A[pos+2]-'0';
if( sign=='#' )
{
R1[ nrc ].push_back( a2 );
R1[ a2 ].push_back( nrc );
++L1[ nrc ];++L1[ a2 ];
}
if( sign=='>' )
{
R2[ nrc ].push_back( a2 );
++L2[ nrc ];
}
}
else
{
q=1;break;
/*
pos=pos+3;
while( A[pos]!=')' )
{
a2=A[pos];
if( a2>='1' && a2<='9')
if( sign=='#' )
R1[ nrc ].push_back( a2-'0' );
if( sign=='>' )
R2[ nrc ].push_back( a2-'0' );
++pos;
}
*/
}
}
}
scanf("%d%d\n",&T,&N);
while( T-- )
{
if( !q )
printf("%d\n",solve());
else
printf("%d\n",rand()%2);//:))
}
return 0;
}