Logo
(追記) (追記ここまで)

26356번 - Knight Moves – Gold Edition 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB89625366.250%

문제

You have a chessboard of size N x N. The rows and columns are numbered from 1 to N. In a cell located at row R1 and Column C1, a knight is starting his journey. The knight wants to go to the cell located at row R2 and Column C2. Move the knight from the starting cell to this destination cell with minimum number of moves.

As a reminder, a knight's jump moves him 2 cells along one of the axes, and 1 cell along the other one. In other words, if a knight is at (A,B), it may move to (A-2,B -1), (A-2, B+1), (A+2, B-1), (A+2, B+1), (A-1, B-2), (A+1,B-2), (A-1, B+2) or (A+1, B+2). Of course, the knight cannot leave the board.

Given N, R1, C1, R2 and C2, determine the minimum number of steps necessary to move the knight from (R1, C1) to (R2, C2).

입력

The first input line contains a positive integer, T, indicating the number of test cases. Each case consists of a line containing five integers N (3 ≤ N ≤ 20), R1, C1, R2 and C2 (1 ≤ R1, C1, R2, C2 ≤ N).

출력

For each test case, first output “Case #i:” where i is the test case number, starting with 1. Then, output the minimum number of steps needed to move the knight from (R1, C1) to (R2, C2). Assume that there will always be a solution, i.e., it’s possible to move the knight from its starting cell to its destination cell. Leave a blank line after the output for each test case. Follow the format illustrated in Sample Output.

제한

예제 입력 1

2
5 1 1 2 3
5 1 1 2 2

예제 출력 1

Case #1: 1
Case #2: 4

힌트

출처

University > University of Central Florida > 2011 Local Programming Contest 8번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /