UVA Knight Moves
题目例如以下:
| 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的更多相关文章
- UVA 439 Knight Moves(BFS)
Knight Moves option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=3 ...
- UVA 439 Knight Moves --DFS or BFS
简单搜索,我这里用的是dfs,由于棋盘只有8x8这么大,于是想到dfs应该可以过,后来由于边界的问题,TLE了,改了边界才AC. 这道题的收获就是知道了有些时候dfs没有特定的边界的时候要自己设置一个 ...
- UVA 439 Knight Moves
// 题意:输入标准国际象棋棋盘上的两个格子,求马最少需要多少步从起点跳到终点 BFS求最短路: bfs并维护距离状态cnt, vis记录是否访问过 #include<cstdio> ...
- 【UVa】439 Knight Moves(dfs)
题目 题目 分析 没有估价函数的IDA...... 代码 #include <cstdio> #include <cstring> #include <a ...
- uva 439 Knight Moves 骑士移动
这道题曾经写过,bfs.用队列,不多说了,上代码: #include<stdio.h> #include<stdlib.h> #include<string.h> ...
- Knight Moves UVA - 439
A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the sh ...
- Knight Moves
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- HDU 1372 Knight Moves
最近在学习广搜 这道题同样是一道简单广搜题=0= 题意:(百度复制粘贴0.0) 题意:给出骑士的骑士位置和目标位置,计算骑士要走多少步 思路:首先要做这道题必须要理解国际象棋中骑士的走法,国际象棋中 ...
- [宽度优先搜索] HDU 1372 Knight Moves
Knight Moves Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
随机推荐
- 李洪强漫谈iOS开发[C语言-018]-scanf函数
- (?m)
centos6.5:/root/sbin#cat -n vv 1 192.168.11.186,192.168.11.187 35199,3306 Dec 7, 2016 11:40:02.75052 ...
- 更新你的jar包
jar文件:/home/resin.jar需更新包中com/caucho/server/port/Port.class类文件 方法1:jar uf resin.jar com/caucho/serve ...
- jdk1.7升级到jdk1.8后出错: [ERROR] javadoc: warning - Multiple sources of package comments found for package
from: http://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html [ERROR] javadoc: warnin ...
- bzoj3878
当初只会暴力,现在差不多觉得水了显然离线处理,对输入的数排序然后会发现不管怎么修改都是结果总是单调不降的对于每次处理,我们只要找到那段越界的即可显然上线段树,话说jsoi这么喜欢线段树?下面在bzoj ...
- Arch linux安装
安装archlinux可参考: http://blog.sina.com.cn/s/blog_69e5d8400101bqlj.html http://www.cnblogs.com/mad/p/32 ...
- Xcode7工程改名
0: 先把原工程压缩个zip包备份一份. 1:在Project navigator中, 选择旧工程名字, 再次点击, 修改. 会弹出提示框. 直接点击确认. (Xcode7.1.1中经常导致Xcode ...
- njust oj triple 莫比乌斯反演
分析:令f(x)为1到n的gcd(i,j)==x的个数 F(x)为1到n的x|gcd(i,j)的对数 显然F(n)=∑n|df(d) 然后由莫比乌斯反演可得f(n)=∑n|d μ(d/n)*F(d) ...
- HDU5647 DZY Loves Connecting 树形DP
(先奉上jcvb大神的官方题解)BC 76 div 1 1002 对于每个结点i,统计出f[i]表示包含i的连通集有多少个,那么容易看出答案就是所有f[i]的和. 要计算f[i]是经典的树形DP问题. ...
- 2015美团网 哈工大 第k个排列
leetcode 上的Permutation Sequence 下面是可执行代码 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 以1 开头 123,132,共2!个数 2 开 ...