Pagini recente » Cod sursa (job #1273934) | Cod sursa (job #737050) | Cod sursa (job #2713625) | Cod sursa (job #2816062) | Cod sursa (job #2110178)
#include <bits/stdc++.h>
using namespace std;
const int mxn = 50 + 10;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, k, x2, y2;;
int a[ mxn ][ mxn ];
bool v[ mxn ][ mxn ];
int rest[ mxn ][ mxn ];
int c[ mxn ][ mxn ];
void lee(int x1, int y1){
queue< int > xx, yy;
xx.push( x1 );
yy.push( y1 );
v[ x1 ][ y1 ] = 1;
c[ x1 ][ y1 ] = 1;
int x, y, nx, ny;
while(!xx.empty()){
x = xx.front();
y = yy.front();
xx.pop();
yy.pop();
if(x == x2 && y == y2)
xx = queue< int >();
else{
for(int i = 0; i < 4; i++){
nx = x + dx[ i ];
ny = y + dy[ i ];
if(a[ nx ][ ny ] && v[ nx ][ ny ] == 0){
v[ nx ][ ny ] = 1;
c[ nx ][ ny ] = c[ x ][ y ] + 1;
xx.push( nx );
yy.push( ny );
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio( false );
cin.tie( 0 );
ifstream cin("kdrum.in");
ofstream cout("kdrum.out");
int x1, y1;
cin>> n >> m >> k;
cin>> x1 >> y1 >> x2 >> y2;
for(int i = 1; i <= n; i++)
for(int j = 1, aux; j <= m; j++){
cin>> a[ i ][ j ];
}
lee(x1, y1);
cout<< c[ x2 ][ y2 ];
return 0;
}