Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

Блог пользователя TooWeak_TooSlow

Автор TooWeak_TooSlow, история, 8 лет назад, По-английски

Hello Everyone, I am trying to solve this problem. but not able to come up with a solution. can someone help me with solving the problem any approach/hint.

Problem Statement: Given a square chessboard of N x N size, the position of Knight and position of a target is given. We need to find out minimum steps a Knight will take to reach the target position. Only Perpendicular Moves Are Allowed.

Constraints:

1<=N<=150. 0<=StartX<=64 0<=StartY<=64

0<=EndX<=64 0<=EndY<=64

StartX and StartY Indicate Starting Location. EndX and Endy Indicate Ending Location.

Test Case:

Input:

N=8 startX and StartY = 0,5

endX and endY = 6,5

output: 3

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

How is the output 3?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Looks like straightforward bfs

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Represent the grid as a graph and do a breadth first search from the starting point.