Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int maxn = 1e3 + 5;
- int MoveX[8] = {-2, -2, -1, -1, 1, 1, 2, 2},
- MoveY[8] = {-1, 1, -2, 2, -2, 2, -1, 1};
- int Board[maxn][maxn];
- int n, m, bx, by, ex, ey;
- void BFS(int x, int y)
- {
- Board[x][y] = 1;
- queue<pair<int,int> > q;
- q.push(make_pair(x, y));
- while (!q.empty())
- {
- pair<int,int> p;
- p = q.front();
- q.pop();
- for(int i = 0 ; i < 8 ; i++)
- {
- if(1 < p.first + MoveX[i] and p.first + MoveX[i] <= n
- and 1 < p.second + MoveY[i] and p.second + MoveY[i] <= m
- and Board[p.first + MoveX[i]][p.second + MoveY[i]] == 0)
- {
- q.push(make_pair(p.first + MoveX[i], p.second + MoveY[i]));
- Board[p.first + MoveX[i]][p.second + MoveY[i]] = Board[p.first][p.second] + 1;
- }
- }
- }
- }
- int main()
- {
- cin >> n >> m >> bx >> by >> ex >> ey;
- BFS(bx, by);
- cout << Board[ex][ey] - 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement