cswork / OA打开练习工作台

IntuitOA #14

Jumping Kady (Intuit India)

估计中等可在线判题

考点(AI 标注)最短路位运算

On an m×n grid, every jump must cover exactly X units (Euclidean distance). Find the minimum number of jumps from the start to the target without jumping off the board; return -1 if the target is unreachable. The explanation of the fixed source example describes the target as (2,5), but its input mistakenly gave the intermediate point (6,2), so the example's u,v are corrected to 2,5.

输入格式

A single line with seven integers m n X p q u v: the number of rows, the number of columns, the jump distance, and the start and target coordinates. Ranges follow the source constraints.

输出格式

Output the minimum number of jumps; output -1 if the target is unreachable.

样例 1

输入:

6 5 5 1 2 2 5

输出:

2

样例 2

输入:

2 2 1 1 1 2 2

输出:

2

样例 3

输入:

6 5 5 1 2 1 2

输出:

0

样例说明

Precompute the integer offsets satisfying dr²+dc²=X², then run BFS over the board cells.