题目例如以下:

Knight Moves 

A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of
n squares on a chessboard exactly once. He thinks that the most difficult part of the problem is determining the smallest number of knight moves between two given squares and that, once you have accomplishedthis, finding the tour would be easy.

Of course you know that it is vice versa. So you offer him to write a program that solves the "difficult" part.

Your job is to write a program that takes two squares a and b as input and then determines the number of knight moves on a shortest route from
a to b.

Input Specification

The input file will contain one or more test cases. Each test case consists of one line containing twosquares separated by one space. A square is a string consisting of a letter (a-h) representing thecolumn and a digit (1-8) representing
the row on the chessboard.

Output Specification

For each test case, print one line saying "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.

模拟象棋里马的前进,求从象棋一点到还有一点马的最短路径长度。简单的宽搜1A了。。。

AC的代码例如以下:

UVA Knight Moves的更多相关文章

  1. UVA 439 Knight Moves(BFS)

    Knight Moves option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=3 ...

  2. UVA 439 Knight Moves --DFS or BFS

    简单搜索,我这里用的是dfs,由于棋盘只有8x8这么大,于是想到dfs应该可以过,后来由于边界的问题,TLE了,改了边界才AC. 这道题的收获就是知道了有些时候dfs没有特定的边界的时候要自己设置一个 ...

  3. UVA 439 Knight Moves

      // 题意:输入标准国际象棋棋盘上的两个格子,求马最少需要多少步从起点跳到终点 BFS求最短路: bfs并维护距离状态cnt, vis记录是否访问过 #include<cstdio> ...

  4. 【UVa】439 Knight Moves(dfs)

    题目 题目     分析 没有估价函数的IDA......     代码 #include <cstdio> #include <cstring> #include <a ...

  5. uva 439 Knight Moves 骑士移动

    这道题曾经写过,bfs.用队列,不多说了,上代码: #include<stdio.h> #include<stdlib.h> #include<string.h> ...

  6. Knight Moves UVA - 439

    A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the sh ...

  7. Knight Moves

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  8. HDU 1372 Knight Moves

    最近在学习广搜  这道题同样是一道简单广搜题=0= 题意:(百度复制粘贴0.0) 题意:给出骑士的骑士位置和目标位置,计算骑士要走多少步 思路:首先要做这道题必须要理解国际象棋中骑士的走法,国际象棋中 ...

  9. [宽度优先搜索] HDU 1372 Knight Moves

    Knight Moves Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

随机推荐

  1. 中国海洋大学第四届朗讯杯高级组 A Rocky

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2718&cid=1203 题意:给你一个m乘n的格子阵,从一边进去,直线往前走,如果前边有 ...

  2. java路径中的空格问题(转)

    java路径中的空格问题 1. URLTest.class.getResource("/").getPath(); URLTest.class.getResource(" ...

  3. git push origin master、git pull出现如下错误

    git push origin master出现如下错误: Counting objects: , done. Writing objects: % (/), bytes, done. Total ( ...

  4. bzoj2565

    网络流就先告一段落了 在进行其他训练之前,我决定先练一道后缀数组(对这个我还是比较有自信的) 虽然之前没用后缀数组解决过回文问题,但是稍微想想就知道, 要解决最长双倍回文,首先要解决最长回文序列, 要 ...

  5. 【转】win7 旗舰版激活密钥

    原文网址:http://zhidao.baidu.com/question/1496641289562471179.html 旗舰版KH2J9-PC326-T44D4-39H6V-TVPBYTFP9Y ...

  6. java类转化为json对象

    方式一:使用jar包,直接转化成json格式,再使用outwrite写到jsp中 先说说要使用到的包commons-beanutils.jar.commons-collections.jar.comm ...

  7. 处理MVC中默认的Json方法返回时间的问题

    利用 Json方法返回 数据时,如果有时间格式,会变成 "\/Date(1369419656217)\/" 这个样子,问了同事找到个解决方法 using Newtonsoft.Js ...

  8. 看懂SqlServer查询计划

    看懂SqlServer查询计划 阅读目录 开始 SQL Server 查找记录的方法 SQL Server Join 方式 更具体执行过程 索引统计信息:查询计划的选择依据 优化视图查询 推荐阅读-M ...

  9. 两种应该掌握的排序方法--------2.quick Sort

    介绍 http://zh.wikipedia.org/wiki/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F 用些里面的c++ 实现,感觉这个空间复杂度比较小.还挺好 in ...

  10. 《深度探索C++对象模型》学习笔记

    1.转型其实是一种编译器指令, 大部分情况下它并不改变一个指针所含的真正地址,它只影响"被指出之内存的大小和内容"的解释方式. 2.Global objects的内存保证会在程序启 ...