1505_KnightMoves

2022-5-16 18:17| 发布者: Hocassian| 查看: 49| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-2-89503864157900-Problem List-采集的数据-后羿采集器.html

Pro.ID

1505

Title

Knight Moves

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=1505

AC

130

Submit

235

Ratio

55.32%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)
  • 描述

    Alice正在专心孜孜地研究国际象棋中的"骑士旅行问题"(Traveling Knight Problem,简称TKP)。TKP就是要寻找遍历一个n阶正方形棋盘所有格子的最短回路,即访问所有格子一次且仅一次,最后回到起点。Alice觉得这个问题最难的部分就是:判定骑士从某个格子走到另一个格子所需的最少步数,一旦解决了这个问题,TKP问题就容易解决了。

    你决定帮Alice写一个程序来解决这个"最难的部分"。具体要做的就是:读入两个格子a和b,然后计算出骑士从a走到b最少需要走多少步。

    输入

    输入有多个测试用例。每个测试用例占一行,有两个格子的编号,它们之间用一个空格分隔。格子的编号是以一个字母开头(a至h)表示棋盘的列号,接着一个数字(1至8)表示棋盘的行号。

    输出

    Description

    Alice正在专心孜孜地研究国际象棋中的"骑士旅行问题"(Traveling Knight Problem,简称TKP)。TKP就是要寻找遍历一个n阶正方形棋盘所有格子的最短回路,即访问所有格子一次且仅一次,最后回到起点。Alice觉得这个问题最难的部分就是:判定骑士从某个格子走到另一个格子所需的最少步数,一旦解决了这个问题,TKP问题就容易解决了。

    你决定帮Alice写一个程序来解决这个"最难的部分"。具体要做的就是:读入两个格子a和b,然后计算出骑士从a走到b最少需要走多少步。

    Input

    输入有多个测试用例。每个测试用例占一行,有两个格子的编号,它们之间用一个空格分隔。格子的编号是以一个字母开头(a至h)表示棋盘的列号,接着一个数字(1至8)表示棋盘的行号。

    Output

    为每个测试用例输出一行"To get from xx to yy takes n knight moves."。具体请参阅输入和输出样例。

    Sample Input

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

    Sample Output

    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.

    Hint

    请了解清楚国际象棋中骑士(即马)的行走方式。

    Source

    样例输入

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

    样例输出

    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.

    提示

    请了解清楚国际象棋中骑士(即马)的行走方式。


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部