Cod sursa(job #1639526)

Utilizator ShayTeodor Matei Shay Data 8 martie 2016 12:43:56
Problema Castel Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.27 kb
#include    <iostream>
#include    <fstream>
#include    <queue>

using namespace std;
ifstream fin ("castel.in");
ofstream fout ("castel.out");

int m, n, k, i, j, Map[100][100], stopx, stopy, numar_chei, startx, starty;
int di[4] = {0,0,1,-1 };
int dj[4] = {-1,1,0,0 };
queue < pair < int, int > > coada;
void citire ()

{ fin >> m >> n >> k;
    for ( i = 1 ; i <= m  ; i++)
       for ( j = 1 ; j <= n ; j++ )
         fin >> Map[i][j];


}

bool OK ( int i, int j )

{ if (i > m || j > n || i < 1 || j < 1)
    return false;
  return true;

}


void lee ()

{ int starx=i, starty=j;
    int i_urmator, j_urmator;
    Map[startx][starty] = 1;
    coada.push(make_pair(startx,starty));
   while (!coada.empty())
    { i = coada.front().first;
      j = coada.front().second;
      coada.pop();
      for ( int directie = 0 ; directie < 4 ; directie++)
        {   i_urmator = i + di[directie];
            j_urmator = j + dj[directie];
            if (OK(i_urmator, j_urmator))
          {Map[i_urmator][j_urmator]=Map[i][j]+1;
            coada.push(make_pair(i_urmator,j_urmator));
           }
        }

    }



}

int main()
{
  citire();
  stopx = m;
  stopy = n;
  lee();
  fout << Map[stopx][stopy]-4;

    return 0;
}