| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
马的路径问题 谁会做啊 帮忙下在m行n列棋盘的S点处有一中国象棋马,给出棋盘上的另一点T,设T在S的右边(如下图所示)。规定马走日字且只能向右走,要从S走到T,马至少要走多少步? 6行7列棋盘: Input 输入的第一行是一个正整数k,表示测试例个数。接下来的k行为k个测试例的数据,每个测试例的数据占一行,含6个整数,依次为: m, n, si, sj, ti, tj,(1<=m, n<=1000,1<=si, ti<=m, 1<=sj, tj<=n, sj<tj),其中m和n分别表示棋盘的行数和列数,si和sj分别表示点S所在位置的行号和列号,ti和tj分别表示点T所在位置的行号和列号,整数之间用一个空格隔开。 Output 对于每个测试例输出一行,含一个整数,表示马从S点向右方向走到T点至少要走的步数,当不存在路径时,输出-1。 Sample Input 2 6 7 4 2 2 7 5 5 3 1 3 2 Sample Output 3 -1 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator