Cod sursa(job #21766)

Utilizator sigridMaria Stanciu sigrid Data 24 februarie 2007 12:20:36
Problema Amlei Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.48 kb
#include<fstream.h>
#define dim 25001
ifstream f("amlei.in");
ofstream g("amlei.out");
int n,t,u,i,v[dim],tt,uu,x,w[dim],ok,j,k,l,ok3,cont1,cont2;
void sort(int x,int y,int vv[dim])
{int nn,ok2=0,poz,man;
   nn=y-1;
   do
    {ok2=0;
     for(l=x;l<=nn;l++)
      if(vv[l]>vv[l+1])
	{ok2=1;
	 man=vv[l];
	 vv[l]=vv[l+1];
	 vv[l+1]=man;
	 poz=l;
	}
     nn=poz;
    }
   while(ok2);
}
int comp1(int x,int y,int vv[dim])
{int mm=0;
 for(k=0;k<n;k++)
  if(vv[x+k]==vv[y+k]) mm++;
 if(mm==n) return 0;
return 1;
}
int comp2(int a,int b,int vv[dim])
{int comparatii=0;
 for(l=1;l<=a;l=l+n) if(comp1(l,b,vv)) comparatii++;
 if((comparatii==(a/n))&&a) return 1;
return 0;
}
int main()
{while(f>>n>>t>>u)
   {ok3=1;cont1=cont2=1;
    tt=t*n;uu=u*n;
    for(i=1;i<=tt;i++)
     {f>>v[i];
      if(i%n==0)
	{sort((i-n+1),i,v);
	 if(comp2((i-n),(i-n+1),v)) cont1++;
	}
     }
    for(i=1;i<=uu;i++)
      {ok=1;
       f>>w[i];
       if(i%n==0)
	{sort((i-n+1),i,w);
	 if(comp2((i-n),(i-n+1),w)) cont2++;
	 k=1;j=1;
	 while((j<=tt)&&(ok!=2)&&(k<=n))
	  {l=i-n+1;
	   if(n==1) {if(v[j]!=w[l]) {ok=0;j=k*n;}}
	   else
	      while((j%n)&&ok)
		{if(v[j]!=w[l]) {ok=0;j=k*n;}
		 j++;l++;
		}
	   if(ok) {ok=2;ok3=1;}
	     else {ok=1;ok3=0;}
	   k++;
	  }
	}
       if(ok3==0)
	  while(i<uu)
	   {f>>x;i++;
	   }
      }
    if((!ok3)||(cont1!=cont2)) g<<"NU"<<'\n';
     else if((ok3)&&(cont1==cont2))g<<"DA"<<'\n';
   }
f.close();
g.close();
return 0;
}