寒假学习第二天

额,今天没什么想说的,直接上题吧,来个简单点的(偷下懒)。

                                                            Background
Mr Somurolov, fabulous chess-gamer indeed, asserts that no one else but him can move knights from one position to another so fast. Can you beat him?
The Problem
Your task is to write a program to calculate the minimum number of moves needed for a knight to reach one point from another, so that you have the chance to be faster than Somurolov.
For people not familiar with chess, the possible knight moves are shown in Figure 1.

输入

The input begins with the number n of scenarios on a single line by itself.
Next follow n scenarios. Each scenario consists of three lines containing integer numbers. The first line specifies the length l of a side of the chess board (4 <= l <= 300). The entire board has size l * l. The second and third line contain pair of integers {0, ..., l-1}*{0, ..., l-1} specifying the starting and ending position of the knight on the board. The integers are separated by a single blank. You can assume that the positions are valid positions on the chess board of that scenario.

输出

For each scenario of the input you have to calculate the minimal amount of knight moves which are necessary to move from the starting point to the ending point. If starting point and ending point are equal,distance is zero. The distance must be written on a single line.

                                           

翻译:

                                                                背景
索穆罗洛夫先生确实是一位出色的国际象棋玩家,他断言,除了他之外,没有人能如此快速地将骑士从一个位置移动到另一个位置。你能打败他吗?


问题:
你的任务是编写一个程序来计算骑士从一个点移动到另一个点所需要的最小移动次数,这样你就有机会比索穆罗洛夫更快。
对于不熟悉国际象棋的人,可能的骑士动作如图1所示。


输入:

输入以单行上的n个场景开始。
接下来是n个场景。每个场景由包含整数的三行组成。第一行指定棋盘一侧的长度l(4<=l<=300)。整个电路板的大小为l*l。第二行和第三行包含一对整数{0,…,l-1}*{0,…,l-1},指定骑士在电路板上的起始和结束位置。

整数由一个空格分隔。你可以假设这些位置是该场景中棋盘上的有效位置。

输出:

对于输入的每个场景,你必须计算从起点移动到终点所需的最少骑士移动量。若起点和终点相等,则距离为零。

距离必须写在一行上。
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值