#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.10.19 NOIP模拟 加密(模拟)

    传送门 直接按hashhashhash函数反着算回去就行了. 加法用exgcdexgcdexgcd,异或直接枚举二进制位. 代码

  2. tp5自动生成目录

    1.// 定义应用目录 define('APP_PATH', __DIR__ . '/../application/'); // 加载框架引导文件 require __DIR__ . '/../thi ...

  3. spring boot入门与进阶

    视频课程包含: SpringBoot入门.SpringBoot进阶.Spring Cloud微服务.Spring Ecosystem 微服务相关.Spring Boot 入门 IDEA 版本.Spri ...

  4. MySQL-5.7.10主主同步的安装和配置

    目录 目录 1 1. 安装 1 2. 修改MySQL的root密码 4 3. mysqld_safe和mysql.server 4 4. 主主同步配置 4 4.1. 创建同步用户 4 4.2. my. ...

  5. 【翻译】使用Vuex解决Vue中的身份验证

    翻译原文链接:https://scotch.io/tutorials/handling-authentication-in-vue-using-vuex 我的翻译小站:https://www.zcfy ...

  6. 【翻译】JavaScript循环和作用域

    我的翻译小站:https://www.zcfy.cc/article/javascript-loops-and-scope 翻译原文链接:https://flaviocopes.com/javascr ...

  7. 伪共享(False Sharing)

    原文地址:http://ifeve.com/false-sharing/ 作者:Martin Thompson  译者:丁一 缓存系统中是以缓存行(cache line)为单位存储的.缓存行是2的整数 ...

  8. MySQL 分表和分区

    1.为什么需要分表和分区 在开发的过程中,经常会遇到大表的情况,所谓的大表是指存储了百万级乃至千万级条记录的表.这样的表过于庞大,导致数据库在查询和插入的时候耗时太长,如果涉及联合查询的情况,性能更加 ...

  9. android插件化简述

    2015年是Android插件化技术突飞猛进的一年,随着业务的发展各大厂商都碰到了Android Native平台的瓶颈: 从技术上讲,业务逻辑的复杂导致代码量急剧膨胀,各大厂商陆续出到65535方法 ...

  10. 通过hbase实现日志的转存(MR AnalyserLogDataRunner和AnalyserLogDataMapper)

    操作代码(提前启动集群(start-all.sh).zookeeper(zkServer.sh start).启动历史任务服务器(mr-jobhistory-daemon.sh start histo ...