Răspuns :
#include <fstream>
#include <queue>
#include <iostream>
using namespace std;
ifstream fin("gigelajungeacasa.in");
ofstream fout("gigelajungeacasa.out");
queue < pair < int, int > > q;
int a[1002][1002];
int di[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dj[] = {0, 1, 1, 1, 0, -1, -1, -1};
int n, m, k;
int x1, y1, x2, y2;
int iy, jy, ib, jb;
void citire()
{
int i, j;
fin >> n >> m >> k;
fin >> x1 >> y1 >> x2 >> y2;
fin >> iy >> jy >> ib >> jb;
//cout << iy << " " << jy << " " << ib << " " << jb;
a[iy][jy] = -1;
a[ib][jb] = -1;
int x, y;
for(i = 1; i <= k; i++)
{
fin >> x >> y;
a[x][y] = -1;
}
}
void filll(int i, int j)
{
int k;
q.push(make_pair(i, j));
while(!q.empty())
{
i = q.front().first;
j = q.front().second;
q.pop();
for(k = 0; k < 8; k++)
{
int nexti = i + di[k], nextj = j + dj[k];
if(a[nexti][nextj] == 0)
{
a[nexti][nextj] = a[i][j] + 1;
if(nexti == x2 && nextj == y2)
{
fout << a[nexti][nextj];
}
q.push(make_pair(nexti, nextj));
}
}
}
}
void gard()
{
int i, j;
for(i = 0; i <= n + 1; i++)
{
a[i][0] = -1;
a[i][m + 1] = -1;
}
for(j = 0; j <= m + 1; j++)
{
a[0][j] = -1;
a[n + 1][j] = -1;
}
}
int main()
{
citire();
gard();
filll(x1, y1);
fin.close();
fout.close();
return 0;
}
Vă mulțumim pentru vizita pe site-ul nostru dedicat Informatică. Sperăm că informațiile oferite v-au fost de ajutor. Nu ezitați să ne contactați pentru orice întrebare sau dacă aveți nevoie de asistență suplimentară. Vă așteptăm cu drag data viitoare și nu uitați să ne adăugați la favorite!