简单BFS题目 主要是读懂题意

和中国的象棋中马的走法一样,走日字型,共八个方向

我最初wa在初始化上了。。。。以后多注意。。。

代码:

 #include <iostream>
#include <cstdio>
#include<cstdlib>
#include <cstring>
#include<queue>
using namespace std;
char a[],b[];
int map[][];
int end_x,end_y;
int d[][]={{-,},{-,-},{,},{,-},{-,},{-,-},{,},{,-}};
class node
{
public:
int x;
int y;
int step;
friend bool operator <(node a,node b)
{
return a.step>b.step;
}
}cur,next;
priority_queue<node> q;
void init()
{
for(int i=;i<;i++)
for(int j=;j<;j++)
map[i][j]=;
}
void bfs()
{
while(!q.empty())
{
cur=q.top();
q.pop();
if(cur.x==end_x&&cur.y==end_y)
{
printf("To get from %s to %s takes %d knight moves.\n", a,b,cur.step);
return ;
}
for(int i=;i<;i++)
{
int x=cur.x+d[i][];
int y=cur.y+d[i][];
if(x>||x<||y>||y<||map[x][y]==) continue;
next.x=x;
next.y=y;
map[x][y]=;
next.step=cur.step+;
q.push(next);
}
}
}
int main()
{
while(scanf("%s %s",a,b)!=EOF)
{
init();
while(!q.empty()) q.pop();
int y1=a[]-'a'+;
int x1=a[]-'';
int y2=b[]-'a'+;
int x2=b[]-'';
cur.x=x1;
cur.y=y1;
cur.step=;
q.push(cur);
end_x=x2;
end_y=y2;
bfs();
}
return ;
}

hdu1372 Knight Moves BFS 搜索的更多相关文章

  1. HDU1372:Knight Moves(BFS)

    Knight Moves Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  2. HDU1372:Knight Moves(经典BFS题)

    HDU1372:Knight Moves(BFS)   Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %l ...

  3. HDU-1372 Knight Moves (BFS)

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

  4. HDU1372 Knight Moves(BFS) 2016-07-24 14:50 69人阅读 评论(0) 收藏

    Knight Moves Problem Description A friend of you is doing research on the Traveling Knight Problem ( ...

  5. poj2243 &amp;&amp; hdu1372 Knight Moves(BFS)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接: POJ:http: ...

  6. (step4.2.1) hdu 1372(Knight Moves——BFS)

    解题思路:BFS 1)马的跳跃方向 在国际象棋的棋盘上,一匹马共有8个可能的跳跃方向,如图1所示,按顺时针分别记为1~8,设置一组坐标增量来描述这8个方向: 2)基本过程 设当前点(i,j),方向k, ...

  7. POJ 1915 Knight Moves(BFS+STL)

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

  8. UVA 439 Knight Moves(BFS)

    Knight Moves option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=3 ...

  9. HDU 1372 Knight Moves(BFS)

    题目链接 Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) whe ...

随机推荐

  1. Failed to connect to Xilinx hw_server. Check if the hw_server is running and correct TCP port is used.

    Failed to connect to Xilinx hw_server. Check if the  hw_server is running and correct TCP port is us ...

  2. Java 对象序列化和反序列化

         之前的文章中我们介绍过有关字节流字符流的使用,当时我们对于将一个对象输出到流中的操作,使用DataOutputStream流将该对象中的每个属性值逐个输出到流中,读出时相反.在我们看来这种行 ...

  3. php中奖算法逻辑

    最近公司有两个活动, 一个是砸蛋活动, 另一个是转盘活动. 后台这边需要做接口进行对接,当用户在前台点击进行抽奖的时候,发送AJAX请求给后台,后台进行业务处理包括记录用户中奖信息,然后返回json格 ...

  4. Windows 10 IoT Serials 8 – 如何改变UWP应用的目标平台

    Windows Insider计划直接加速了Windows系统的迭代,缩短了系统发布的周期.就Windows 10 IoT Core而言,迭代的速度和Windows 10 for PC.Windows ...

  5. 大数据时代日志分析平台ELK的搭建

    A,首先说说ELK是啥,  ELK是ElasticSearch . Logstash 和 Kiabana 三个开源工具组成.Logstash是数据源,ElasticSearch是分析数据的,Kiaba ...

  6. WPF之路二: button添加背景图片点击后图片闪烁问题

    在为button添加背景图片的时候,点击后发现图片闪烁,我们仔细观察,其实Button不仅仅只是在点击后会闪烁,在其通过点击或按Tab键获得焦点后都会闪烁,而通过点击其他按钮或通过按Tab键让Butt ...

  7. 体验VS2017的Live Unit Testing

    相对于传统的Unit Test,VS2017 带来了一个新的功能,叫Live Unit Testing,从字面意思理解就是实时单元测试,在实际的使用中,这个功能就是可以在编写代码的时候进行实时的bac ...

  8. require.js入门

    小颖目前所在的公司在用require.js,小颖一只说要写个小demo,今天抽空把自己写的小demo分享出来,希望对初学者有一些帮助,嘻嘻 学习资料: CSDN上的一篇文章:使用RequireJS优化 ...

  9. javaScript 基础学习笔记

    边看视频和书记得有点杂. 1.插入JS标签 一种是在文档中插入<script></script>标签.另一种是把javaScript代码放在.js文件中.放在head中如. & ...

  10. windows下使用wineshark分析抓取本地回环包

    ## 摘要 由于windows系统没有提供本地回环网络的接口,用Wireshark监控网络的话看不到localhost的流量. 想要获取本地的网络数据包,可以通过一款小巧的开源软件RawCap来进行抓 ...