#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. 第二篇博客 wordcount

    1.首先 附上Github项目地址:https://github.com/June1104/WordCount 2.psp表格 PSP2.1表格 PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 ...

  2. 如何使用css来让图片居中不变形 微信小程序和web端适用

    图片变形很多人祭奠出了妖魔鬼怪般的各种大法,比如使用jq来写,或者使用css表达式来写.今天我总结的是使用css3来写,唯一最大缺点就是对一些浏览器版本不够兼容.下面就是关于如何使用css来让图片居中 ...

  3. 2018.09.23 孙悟空大战鲤鱼精(单调队列优化dp)

    描述 孙悟空大战鲤鱼精,孙悟空在通天河遇到鲤鱼精,他嫉恶如仇,看见妖精就手痒(忘了自己是妖精).但是鲤鱼精知道孙悟空的厉害,在孙悟空来到通天河,鲤鱼精就跑到了河对面.于是孙悟空就去追鲤鱼精. 我们可以 ...

  4. vs2010 EF4.0 访问mysql

    需要安装mysql-connector-net-6.3.5 6.8.9的安装完后在dbfirst里找不到对应的提供程序 链接字符串里需要 指定下编码(如果不是gbk的话) <add name=& ...

  5. win7 精简板 安装ardunio uno r3驱动

    http://www.arduino.cn/thread-2350-1-1.html 下载那个64位的 http://www.keyes-robot.cn/forum.php?mod=viewthre ...

  6. jdk1.7和1.8共存的问题(默认1.7)

    参考https://www.cnblogs.com/fxmemory/p/7234848.html 电脑上有了jdk1.7,环境变量配的是1.7,后来再安装了个1.8,结果在cmd-->java ...

  7. js限制上传图片类型和大小

    <script type="text/javascript"> function checkFile(brandLogo){ var file=brandLogo.va ...

  8. DataFrame按行读取:DataFrame之values

    http://blog.csdn.net/u014607457/article/details/51290582 def fill_core(self): RatingTable=pd.read_cs ...

  9. 计算服务器的pv量算法

    如何计算服务器能够承受多大的pv?   你想建设一个能承受500万PV/每天的网站吗? 500万PV是什么概念?服务器每秒要处理多少个请求才能应对?如果计算呢? PV是什么: PV是page view ...

  10. (小数化分数)小数化分数2 -- HDU --1717

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1717 举例: 0.24333333…………=(243-24)/900=73/3000.9545454…… ...