题目例如以下:

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. 如何登录mysql? cmd怎么连接mysql数据库

    Mysql开源数据库,任何人都可以下载安装使用.那么安装好的mysql如何登陆连接mysql数据库呢? 连接mysql数据库的几种方法 一 Mysql命令行连接 一般对于刚刚安装好的mysql,如果勾 ...

  2. QReadWriteLock 读写锁的区别

    QReadWriteLock 这个允许多个进程同时读,但是只有一个写.而且写读不能同时进行. 文档里语焉不详,这是我自己的理解: lockForWrite 为写而锁,就是要修改数据,外人连想进来读数据 ...

  3. 【HDOJ】1088 Write a simple HTML Browser

    题目其实不难,但是要注意题目的要求,当前字数(>0)+当前单词长度+1若超过80则需要回车后,输出当前word,并且重新计数.这道题目的数据感觉比较水,不过测试的时候,最后使用fprintf输出 ...

  4. 函数 xdes_get_state

    得到XDES Entry中状态 /**********************************************************************//** Gets the ...

  5. bzoj1103

    其实这道题和以前在poj上做过的将树映射到树状数组的题目很像 首先不难想到,将一条边从土路修成公路,只对以这条边连接的孩子结点为根的子树有影响: 于是和之前那道poj的题目很像,后序遍历树,对每个节点 ...

  6. 设置oracle11g空表exp导出

    1.Oracle11g默认对空表不分配segment,故使用exp导出Oracle11g数据库时,空表不会导出. 2.设置deferred_segment_creation 参数为FALSE后,无论是 ...

  7. (转)如何正确使用C++多重继承

    http://bigasp.com/archives/486 如何正确使用C++多重继承 2011年06月17日 — Asp J 原创文章,转载请注明:转载自Soul Apogee本文链接地址:如何正 ...

  8. ArcGIS for Android示例解析之高亮要素-----HighlightFeatures

    转自:http://blog.csdn.net/wozaifeiyang0/article/details/7323606 HighlightFeatures 要素高亮化功能,相信有其他gis开发经营 ...

  9. SR4000自带软件修改(二)

    /*----------------------------------------------------------------------------- *   *   版权声明: *   可以 ...

  10. apple公司的潮起潮落——浪潮之巅

    今天代码写不下去的时候,躺在床上看了一下浪潮之巅.翻了一下书目,选了apple公司那一篇. 其实apple公司的事情我已经听过不止一次了,但是每次都是间间断断地听说,都没有系统地了解它到底是经历了怎么 ...