Cod sursa(job #254404)

Utilizator RoflmaoPatru Ovidiu Roflmao Data 7 februarie 2009 11:55:17
Problema Kdrum Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 2 Marime 1.05 kb
#include<iostream.h>
#include<fstream.h>
int main()
{
  fstream f,g;
  long int x[53][53]={0},n,m,k,i,j,x1,x2,y1,y2,xs[1000],ys[1000],count;
  f.open("kdrum.in",ios::in);
  g.open("kdrum.out",ios::out);
  f>>n>>m>>k;
  f>>x1>>y1>>x2>>y2;
  for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
      f>>x[i][j];
  if(k!=1)
  {
    x1=x1-x2;
    y1=y1-y2;
    if(x1<0)
      x1=x1*(-1);
    if(y1<0)
      y1=y1*(-1);
    g<<x1+y1+1;
  }
  else
  {
    x[x1][y1]=-1;
    for(k=1;x[x2][y2]!=-1;k++)
    {
      for(i=1;i<=1000;i++)
      {
	xs[i]=0;
	ys[i]=0;
      }
      count=0;
      for(i=1;i<=n;i++)
	for(j=1;j<=m;j++)
	  if(x[i][j]==-1)
	  {
	    x[i][j]=0;
	    if(x[i+1][j]==1)
	    {  xs[++count]=i+1;  ys[count]=j; }
	    if(x[i-1][j]==1)
	    {  xs[++count]=i-1;  ys[count]=j; }
	    if(x[i][j+1]==1)
	    {  xs[++count]=i;  ys[count]=j+1; }
	    if(x[i][j-1]==1)
	    {  xs[++count]=i;  ys[count]=j-1; }
	  }
      for(i=1;i<=count;i++)
	x[xs[i]][ys[i]]=-1;
    }
    g<<k;
  }
  g.close();
  f.close();
  return 0;
}