Cod sursa(job #21059)

Utilizator sigridMaria Stanciu sigrid Data 22 februarie 2007 21:02:20
Problema Amlei Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.28 kb
#include<fstream.h>
#define dim 25001
//#define dim2 51
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;
void sort(int x,int y,int z)
{if(!z)
  {int nn,ok2=0,poz,man;
   nn=y-1;
   do
    {ok2=0;
     for(l=x;l<=nn;l++)
      if(v[l]>v[l+1])
	{ok2=1;
	 man=v[l];
	 v[l]=v[l+1];
	 v[l+1]=man;
	 poz=l;
	}
     nn=poz;
    }
   while(ok2);
  }
 if(z)
  {int nn,ok2=0,poz,man;
   nn=y-1;
   do
    {ok2=0;
     for(l=x;l<=nn;l++)
      if(w[l]>w[l+1])
	{ok2=1;
	 man=w[l];
	 w[l]=w[l+1];
	 w[l+1]=man;
	 poz=l;
	}
     nn=poz;
    }
   while(ok2);
  }
}
int main()
{
 while(f>>n>>t>>u)
   {ok3=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,0);/*i++;*/}
     }
    for(i=1;i<=uu;i++)
      {ok=1;
       f>>w[i];
       if(i%n==0)
	{sort((i-n+1),i,1);
//	 i++;
	 k=1;j=1;
	 while((j<=tt)&&(ok!=2)&&(k<=n))
	  {//j+=k-2;
	   l=i-n+1;
	   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)
	 do
	   {f>>x;i++;
	   }
	 while(i<uu);
      }
    if(!ok3) g<<"NU"<<'\n';
     else g<<"DA"<<'\n';
   }
f.close();
g.close();
return 0;
}