a758. CPE:Knight Moves (UVa 439)

簡單CPE

時間限制 2000 ms ・ 記憶體限制 256 MB

題目描述

在標準 8×8 西洋棋棋盤上,騎士每步沿一方向移動兩格,再沿垂直方向移動一格。給定起點與終點,求最少騎士步數,路徑不可離開棋盤。

輸入格式

每行兩個棋盤位置,以空白分隔。位置由 a 到 h 的欄字母及 1 到 8 的列數字組成。輸入讀至檔案結束。

輸出格式

每筆輸出 To get from xx to yy takes n knight moves.,其中 xx、yy 是輸入位置,n 是最少步數。即使 n = 1 也使用 moves。

原題:https://onlinejudge.org/external/4/439.pdf

範例測資

範例輸入 1

e2 e4
a1 b2
b2 c3
a1 h8
a1 h7
h8 a1
b1 c3
f6 f6

範例輸出 1

To get from e2 to e4 takes 2 knight moves.
To get from a1 to b2 takes 4 knight moves.
To get from b2 to c3 takes 2 knight moves.
To get from a1 to h8 takes 6 knight moves.
To get from a1 to h7 takes 5 knight moves.
To get from h8 to a1 takes 6 knight moves.
To get from b1 to c3 takes 1 knight moves.
To get from f6 to f6 takes 0 knight moves.
請先登入後再提交程式碼

討論與題解

載入討論區…

更多