Knight Moves
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13222   Accepted: 7418

Description

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 accomplished this, 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

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

Output

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.

Source

 
 
 
解析:题意为求从棋盘a处到b处需要跳动的最少次数。广搜一遍即可,要注意骑士的行走方式。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXEAAAEiCAIAAACA/3WqAAAgAElEQVR4nO2dfXxT1f347+YGFQimtMNSEDPAWtFqoMJCYRIRNV9pR1lRoSpExVpc1crDqFO4K06qUgyCrIYHU3loQQstRSidSESBCr+MDEQ6GCPjMVAKgdISWmk/vz9OuQ1JmtzknntzUz/v1+cPSJOcnJvPeec83XsZQBAEoQcT6g+AIEiHAp2CIAhNfu5OaWlpmTNnL8MYx4zZfPXqtVB/HFnQ0tIye/aeDnBMWPb/MYyRYYx9+665csXZ1NT0008/hfpDBQP3dTQ0OFtaWkL9cfzws3YKl3MMY5w9u2Lv3r3//Oc/m5qa5P+1iUdx8X+4Y/L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bMuWLc8//7xCoXj44YcFrlt5Qhr8mDGbjxw5+v777z/99NMvvPBCfn7+vffe26tXr1tvvfWee+75+uuvhUz/cSmalla8atWquLi4W27JIr8Bn3xS/rvfvXf77b3uuuuuo0ePym1PsCycwrUuhjF267b4nnte5P47YsSfH3jggf/7v/+jmxakRIVi2YoVZSkpKb/+9WsMY3zuuY1bt26dMWNGdHR0t27dMjMzHQ4HxULdOHeugczA9ey54p138gYMGJCT80n//mvOn3dIsOQENx/2rl0XuR72gQPnDB06dMyYMQIPOxkgkIaRk5PTu3fvRx6Zdf/9n2zbtv3o0aN0V3zAZbCwcOGXGzduTEpKUigUAvsLXnHd6sYwxt/97o3Bgwfn5OTk5eXdc889w4YNKy8vFzhJxBWxYMHGt99+m/vZI8sI48ZNeeKJJ6hPCFBBFk6pr2+6//51pHWtXVvy9NPzybHLzv585syZOp1u7NixNTU1FH383Xenb721bZx/yy0fzZ//6c6dO996662+ffsqFIr77rvPYrGIvZR78qSDbMMhkZi44scfq0+dOvXBBx98//33jY2NopqlpaXliSc2kcHOunVfZGTMu+WWT8gq7MyZM1NSUh5//HGBh72lpeXTTw+4Nr8//GFldXX1oUOHXnvtte3bt9OtI5mg7dWrcPPmyqKiotjY2B49eogxOuAGWa7x5JPrvvnmm3379tnt9mvXhO55Gzt2K2kRn3++ISUlpVu3br/5zRwilBUryt58880RI0Y88cQT58+fx7Vk71y7dm3Tpk1FRUVvvfVWXFzcq6++unbt2iVLljz99NNRUVFz585dv349xf0FLS0tdXV1s2fPLigoyMjImDlz5ldffTVr1qw777xzwIABffv2/eijjyRYomtubt6/f//ChQvXrVu3dOnS6dOnz5w5U6vVLlmy5Isvvti/f7/YW++amppKS0tXr1791ltv9e/ff8qUKcXFxUaj8ZlnnomOjv7b3/5WVlZGtooFXcT169fNZnNhYeHnn39eUFCQm5s7Y8aMwYMHFxUVLV26dO/evbTqyE1ATJhQUllZybIsmQOurq6mPjpITa3s23fNxo3b+vf/1FUrc+cWHT9+nMpPUXNz87lz58hXc+eddyoUir/+9a8nT55cvnz5jBkzhg4detttty1dunT16tUUV82oIBentLS0nDx5MikpSalUdu7cOSEh4fnnn+/Xr99tt92mUCgmTpy4YcMGurtFWlpaDh06pNVqe/To0adPn+Tk5ClTpjz11FNqtXrhwoW1tbXS6P+nn35au3Ztv379evToERkZeffdd0+dOjUzM3Pr1q1UNmL6paamZty4cT169CCH/ZVXXrn77ruVSmX37t3/9Kc/7dy5U/g29mvXrv31r38lvYbo6OgRI0ZkZ2dnZmZ+8cUXAoV1c0Va+w4ffbS5rKxs9OjRXbt2HTt27Pnz56m8P4HM7kdGmnbt+vcPP/wwZ86crKys559fQpzy2mtrMzMzrVYrlZWs5ubmZcuWpaSkdO/evU+fPl9//fW1a9fWr18/cODA7t27R0dHv/jii4cOHZLbJn25OAUArl+/fvTo0cmTJz/66KOLFy8+efJkeXn5E088MWXKlI0bN1JMPtcSDx48+P7770+aNOnPf/7znDlz5s6du337drobLv1y9erVbdu26fX64cOHT548uaCgwGq1Up9raI/m5uaTJ09mZ2enpKQYjcbTp09//fXXycnJL7300qZNm2jN7Fy+fPnvf//72LFj77333meffXbRokUHDx6kIk3SyO+4Y/U335zu1GnZ6NEbKioq58+f37NnT6VSuWDBAro/48Rc3bsvX7Nm67PPPjthwoSnnnrqzjvv6tYtj0xFz5w5c/jw4UeOHKHS1K9cubJgwYLx48dnZmYSOTY2Nm7btu2FF17429/+9sMPP0h2Egl/ZOQUALh+/frFixfPnz/f0NDQ3NzsdDpra2sdDofw0amPEq9cuXLx4sWLFy86HI66urqQfEmNjY0XL16sqam5ePFifX29xJcja25uvnTpUm1tLRHZtWvXqB/2lpaWhoaG2tras2fPXrhw4cqVK7R+Xcn6SGzsZ6++alYqP928+fuioiKNRtOtW7cBAwbQXS4k/OEPFWTya/Tox1566aWMjIxXX/2MYYz33ff3VavWkMspmEwmKt1qMki/cOGCw+EgIziy1cDhcFA8hnSRl1MQJFCuXGkkE/y33lrw8cfF33777ahRo3r27BkdHT1z5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yG7o6ITkEQ5GcIOgVBEJqgUxAEoQk6BUEQmqBTEAShCToFQRCaoFMQBKEJOgVBEJqgUxAEoQk6BUEQmqBTEAShCToFQRCaoFMQBKEJOgVBEJqgUxAEoQk6BUEQmqBTEAShCToFQRCaoFMQBKEJOgVBEJr8fxktJZcKG/BkAAAAAElFTkSuQmCC" alt="" />
 
 
 
 
 #include <cstdio>
#include <cstring>
#include <queue>
using namespace std; struct Point{
int x, y;
}s, t;
//骑士行走的方向
int dir[][] = {{, }, {, -}, {-, }, {-, -}, {, }, {-, }, {, -}, {-, -}}; bool inChess(Point a)
{
return a.x >= && a.y >= && a.x < && a.y < ;
} int bfs()
{
if(s.x == t.x && s.y == t.y)
return ;
queue <Point> q;
bool visit[][];
int dis[][];
memset(visit, , sizeof(visit));
q.push(s);
visit[s.x][s.y] = true;
dis[s.x][s.y] = ;
while(!q.empty()){
Point a = q.front();
q.pop();
for(int i = ; i < ; ++i){
Point b;
b.x = a.x + dir[i][];
b.y = a.y + dir[i][];
if(inChess(b) && !visit[b.x][b.y]){
visit[b.x][b.y] = true;
dis[b.x][b.y] = dis[a.x][a.y] + ;
q.push(b);
if(b.x == t.x && b.y == t.y)
return dis[b.x][b.y];
}
}
}
return -;
} int main()
{
char s1[], s2[];
while(~scanf("%s%s", s1, s2)){
s.x = s1[] - 'a';
s.y = s1[] - '';
t.x = s2[] - 'a';
t.y = s2[] - '';
printf("To get from %s to %s takes %d knight moves.\n", s1, s2, bfs());
}
return ;
}

POJ 2243 Knight Moves的更多相关文章

  1. POJ 2243 Knight Moves(BFS)

    POJ 2243 Knight Moves A friend of you is doing research on the Traveling Knight Problem (TKP) where ...

  2. POJ 1915 Knight Moves

    POJ 1915 Knight Moves Knight Moves   Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 29 ...

  3. OpenJudge/Poj 1915 Knight Moves

    1.链接地址: http://bailian.openjudge.cn/practice/1915 http://poj.org/problem?id=1915 2.题目: 总Time Limit: ...

  4. POJ 1915 Knight Moves(BFS+STL)

     Knight Moves Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20913   Accepted: 9702 ...

  5. HDU 2243 Knight Moves

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

  6. POJ2243 Knight Moves —— A*算法

    题目链接:http://poj.org/problem?id=2243 Knight Moves Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  7. 【POJ 2243】Knight Moves

    题 Description A friend of you is doing research on the Traveling Knight Problem (TKP) where you are ...

  8. POJ Knight Moves 2243 x

    Knight Moves Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13974   Accepted: 7797 Des ...

  9. POJ---2243 Knight Moves 使用A*算法的广度优先搜索

    题目链接:http://poj.org/problem?id=2243 启发式搜索:启发式搜索就是在状态空间中的搜索对每一个搜索的位置进行评估,得到最好的位置,再从这个位置进行搜索直到目标.这样可以省 ...

随机推荐

  1. html input type="button" 页面跳转

    <div class="message_text"> <p>你的申请已提交,请耐心等候哦!~</p><br /> <input ...

  2. sb 讲解 (!(~+[])+{})[--[~+""][+[]]*[~+[]] + ~~!+[]]+({}+[])[[~!+[]]*~+[]]

    代码:(!(~+[])+{})[--[~+""][+[]]*[~+[]] + ~~!+[]]+({}+[])[[~!+[]]*~+[]] 输出sb. 分段解析: 首先解析s: (! ...

  3. Jquery实现自动提示下拉框

    1.引入脚本库:     <script type="text/javascript" src="/Jscripts/jquery-1.3.2.js"&g ...

  4. VPN销售管理系统一键安装包

    wget http://d.zmrbk.com/vpn/zmrvpn.sh;chmod +x zmrvph.sh;sh zmrvpn.sh 2>&1 | tee zmrbk.com.lo ...

  5. SQL的集合运算符介绍

    最近学习了SQL SERVER方面的知识,毕竟做Web应用,少不了跟数据库打交道.学习的来源主要是<程序员的SQL金典>这本书. 今天介绍数据库里面的集合运算符,它是指匹配集合的每一个结果 ...

  6. 国外程序员整理的 C++ 资源大全

    摘要:C++是在C语言的基础上开发的一种集面向对象编程.泛型编程和过程化编程于一体的编程语言.应用较为广泛,是一种静态数据类型检查的,支持多重编程的通用程序设计语言. 关于 C++ 框架.库和资源的一 ...

  7. 强大的CImage类

    这下有了CImage类,处理其他类型的图片不再寻找第三方类库了.加载到对话框背景的代码如下:  //从资源里载入背景JPEG图片 HRSRC hRsrc=::FindResource(AfxGetRe ...

  8. Codeigniter开发技巧:连接多个数据库(可实现DB读写分离)

    在开发中,我们有时候会遇到在同一程序中链接多个数据库的需求,这对Codeigniter框架来说是很简单的,我们只需要在 database.php文件中配置少许参数即可. 默认情况下,CI配置的是链接一 ...

  9. HDU 1203 I NEED A OFFER!(01 背包DP)

    点我看题目 题意 : 中文题不详述. 思路 :类似于01背包的DP,就是放与不放的问题,不过这个要求概率,至少得到一份offer的反面就是一份也得不到,所以先求一份也得不到的概率,用1减掉就可以得到所 ...

  10. HDU4714+三分

    题意:给定N个点,每个点有初始位置和初始速度. 问:在哪个时刻 使得所有的点的最大距离值最小. 分析:一开始枚举两两之间的最大值,然后在最大值中求一个最小值...(WA:题意严重理解不清..) 由两点 ...