C++程序设计题:Knight Moves 请高手帮忙,谢谢!

DescriptionBackgroundMrSomurolov,fabulouschess-gamerindeed,assertsthatnooneelsebuthim... Description

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.

Input

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.
Output

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.
Sample Input

3
8
0 0
7 0
100
0 0
30 50
10
1 1
1 1
Sample Output

5
28
0
展开
 我来答
holysll
2011-03-06
知道答主
回答量:67
采纳率:0%
帮助的人:12.3万
展开全部
说明咐槐

背景
主席Somurolov,神话般的国际象棋游戏玩家的确,没有人声称,但他可以从一个位置移动到另一个骑士这么快。你能打败他吗?
存在的问题
你的任务是编写一个程序来计算一个骑士需要达到一个最低点移动从另一个号码,让你有机会快于Somurolov。
国际象棋的人不熟悉,可能骑指简闭士举动,如图1所示。

输入

输入开始本身上的一行数n的情景。
下次覆ñ方案。每个场景包含由三个整数线。第一行指定了一个棋盘侧(4 <=L<= 300)长度L。整板具有尺寸L *湖第二和第三线包含对整数{0,唯裂...,L - 1的} * {0,...,L - 1的}指定了黑板上的骑士开始和结束位置。整数是由一个空白分开。你可以假设的立场是在这种情况下国际象棋棋盘的有效阵地。
输出

对于每个输入情况下,您必须计算出骑士的行动,是必要的,从出发点到终点最低金额。如果起点和终点都是平等的,距离是零。距离必须写在一行。
采样输入


8
0 0
7 0
100
0 0
30 50
10
1 1
1 1
输出范例

5
28
0
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式