#include <iostream>
#include <queue>
using namespace std; int dir[][] = {-,-,-,,,-,,,,-,-,-,,,-,}; struct node
{
int x;
int y;
int step;
node()
{
step = ;
}
}; queue<node> coll; bool mark[][]; node beg;
node end; bool bfs(node p); int main()
{
//freopen("acm.acm","r",stdin);
char s_1[];
char s_2[]; while(cin>>s_1>>s_2)
{
memset(mark,false,sizeof(mark));
beg.x = s_1[] - 'a';
beg.y = s_1[] - '' - ; end.x = s_2[] - 'a';
end.y = s_2[] - '' - ;
coll.push(beg);
mark[beg.x][beg.y] = true;
cout<<"To get from "<<s_1<<" to "<<s_2<<" takes "; while(!coll.empty() && !bfs(coll.front()))
{
coll.pop();
}
while(!coll.empty())
{
coll.pop();
}
cout<<" knight moves."<<endl;
}
} bool bfs(node p)
{
int i;
int j;
if(p.x == end.x && p.y == end.y)
{
cout<<p.step;
return true;
}
int tem_i;
int tem_j;
node tem; for(i = ; i < ; ++ i)
{
tem_i = p.x + dir[i][];
tem_j = p.y + dir[i][];
if(tem_i >= && tem_i < && tem_j >= && tem_j < && !mark[tem_i][tem_j])
{
tem.x = tem_i;
tem.y = tem_j;
tem.step = p.step + ;
mark[tem_i][tem_j] = true;
coll.push(tem);
}
}
return false;
}

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com

POJ 2243的更多相关文章

  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 2243】Knight Moves

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

  3. POJ 2243 Knight Moves

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

  4. POJ 2243 简单搜索 (DFS BFS A*)

    题目大意:国际象棋给你一个起点和一个终点,按骑士的走法,从起点到终点的最少移动多少次. 求最少明显用bfs,下面给出三种搜索算法程序: // BFS #include<cstdio> #i ...

  5. POJ 2243 [SDOI2011]染色 | 树链剖分+线段树

    原题链接 肯定是树链剖分的题啦 树剖怎么做可以看我上一篇博客 如果我们已经剖完了: 然后考虑怎么维护重链和查询 用线段树维护的时候当前区间的区间颜色个数应该等于左儿子+右儿子,但是当左儿子的右端点和右 ...

  6. poj2243 bfs

    O - 上一个题的加强版 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     6 ...

  7. BFS、双向BFS和A*

    BFS.双向BFS和A* Table of Contents 1. BFS 2. 双向BFS 3. A*算法 光说不练是无用的.我们从广为人知的POJ 2243这道题谈起:题目大意:给定一个起点和一个 ...

  8. HDU 3966 & POJ 3237 & HYSBZ 2243 树链剖分

    树链剖分是一个很固定的套路 一般用来解决树上两点之间的路径更改与查询 思想是将一棵树分成不想交的几条链 并且由于dfs的顺序性 给每条链上的点或边标的号必定是连着的 那么每两个点之间的路径都可以拆成几 ...

  9. HDU 3966 & POJ 3237 & HYSBZ 2243 & HRBUST 2064 树链剖分

    树链剖分是一个很固定的套路 一般用来解决树上两点之间的路径更改与查询 思想是将一棵树分成不想交的几条链 并且由于dfs的顺序性 给每条链上的点或边标的号必定是连着的 那么每两个点之间的路径都可以拆成几 ...

随机推荐

  1. 2018.09.26洛谷P3957 跳房子(二分+单调队列优化dp)

    传送门 表示去年考普及组的时候失了智,现在看来并不是很难啊. 直接二分答案然后单调队列优化dp检验就行了. 注意入队和出队的条件. 代码: #include<bits/stdc++.h> ...

  2. 2018.09.17 atcoder Tak and Hotels(贪心+分块)

    传送门 一道有意思的题. 一开始想错了,以为一直lowerlowerlower_boundboundbound就可以解决询问,结果交上去TLE了之后才发现时间复杂度是错的. 但是贪心思想一定是对的,每 ...

  3. Django-组件

    https://www.cnblogs.com/yuanchenqi/articles/8034442.html

  4. APMServ—优秀的PHP集成环境工具

    经常折腾wordpress和各种php开发的cms,免不了要在本地测试这些程序,所以选择一款好的php集成环境就至关重要啦.之前在月光博客上看到有一篇“常见的WAMP集成环境”介绍,然后先后试用过XA ...

  5. 测试-LoadRunner

    1录脚本 设置解析方式,html形式,会精炼成一个函数,此时找有用的url,写出函数:url方式,函数比较多. 参数化 两参数成对时,在脚本处选成对. 加上进程,加上返回值判断. 最后一段接口url, ...

  6. (网络流 模板 Edmonds-Karp)Drainage Ditches --POJ --1273

    链接: http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total ...

  7. (快速幂)Key Set--hdu--5363

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=5363 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  8. no_namespace rename 在C++中是什么意思啊

    #import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("E ...

  9. Linux操作系统文件系统基础知识详解

    一 .Linux文件结构 文件结构是文件存放在磁盘等存贮设备上的组织方法.主要体现在对文件和目录的组织上. 目录提供了管理文件的一个方便而有效的途径. Linux使用标准的目录结构,在安装的时候,安装 ...

  10. 好用的SHELL小编程

    1>判断输入为数字,字符或其他      脚本代码:      检测结果:   2>求平均数:   测试效果:     3>自减输出: 脚本代码: 测试效果:    4>在文件 ...