Knight Moves: Black Edition
Time limit1sMemory limit1024 MB
Given an N by N board with N up to 1e15, find the fewest knight moves between two cells.
- Level
Hard8 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
You have a chessboard of size . The rows and columns are numbered from 1 to . A knight starts on the cell at row and column , and wants to reach the cell at row and column . Move the knight from the starting cell to the destination in the minimum number of moves.
A knight's jump moves it 2 cells along one axis and 1 cell along the other. If the knight is at , it may move to , , , , , , , or . The knight cannot leave the board.
Given , , , , and , determine the minimum number of steps needed to move the knight from to .
Input
The first line contains a positive integer , the number of test cases. Each case is a line with five integers (), , , , and ().
Output
For each test case, print "Case #i:" where is the test case number starting from 1, followed by the minimum number of steps. A solution is guaranteed to exist, so the knight can always reach the destination from the starting cell. Leave a blank line after the output of each test case. Follow the format shown in the sample output.