poj 2243 Knight Moves bfs
来源:互联网 发布:淘宝英伦男装店铺排行 编辑:程序博客网 时间:2024/05/22 06:43
水题,裸的bfs,基本没有要注意的
/*author:jxylang:C/C++university:China,Xidian University**If you need to reprint,please indicate the source***/#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <queue>#define INF 1E9using namespace std;const int dir[8][2]={-2,-1,-2,1,-1,-2,-1,2,1,-2,1,2,2,1,2,-1};int vis[9][9];struct node{ int x,y;};queue<node> q;char aim[3],stt[3];node st,am,now,temp;int i;int main(){ while(~scanf("%s%s",stt,aim)) { memset(vis,0,sizeof(vis)); while(!q.empty())q.pop(); st.x=stt[0]-'a';st.y=stt[1]-'1'; am.x=aim[0]-'a';am.y=aim[1]-'1'; vis[st.x][st.y]=1; q.push(st); while(!q.empty()&&!vis[am.x][am.y]) { now=q.front();q.pop(); for(i=0;i<8;i++) { temp.x=now.x+dir[i][0]; temp.y=now.y+dir[i][1]; if(temp.x<0||temp.x>7||temp.y<0||temp.y>7||vis[temp.x][temp.y])continue; vis[temp.x][temp.y]=vis[now.x][now.y]+1; q.push(temp); } } printf("To get from %s to %s takes %d knight moves.\n",stt,aim,vis[am.x][am.y]-1); }}
- poj 2243 bfs Knight Moves
- poj 2243 Knight Moves bfs
- POJ 2243Knight Moves (bfs)
- POJ 2243 Knight Moves(BFS)
- POJ 2243 Knight Moves bfs || 双向bfs
- POJ-2243(bfs)(Knight Moves )
- poj 2243 -- Knight Moves (bfs)
- POJ 2243 Knight Moves (BFS入门)
- POJ 2243 Knight Moves(BFS或DFS)
- POJ 2243 || HDU 1372:Knight Moves(BFS)
- POJ 2243 || HDU 1372:Knight Moves(BFS)
- POJ 2243 Knight Moves【BFS|A*】
- POJ 2243 Knight Moves(BFS)
- POJ 2243:Knight Moves(双向BFS)
- POJ 1915 Knight Moves bfs
- POJ 1915Knight Moves(BFS)
- poj 1915 Knight Moves(bfs)
- poj 1915 Knight Moves(bfs)
- 自己收藏的一些计算机科学经典书共享--free
- Qt 实现基本布局管理 ---实验
- RHEL/CentOS下的yum的使用
- 分区号段范围分布的判断,号码分布判断
- SVN commit:remains in tree-conflict 错误的解决办法
- poj 2243 Knight Moves bfs
- Android 各类Adapter总结
- html的基础介绍
- int、long、long long取值范围
- 简单标签_侯子腾的个人总结(第十二次课)
- sql server 2008学习笔记
- GCC与MinGW的简单使用
- ecshop 商品属性
- JavaSE第三十四讲:Arrays类解析及数组疑难剖析