BFS POJ2243- Dario
来源:互联网 发布:电脑优化加速软件 编辑:程序博客网 时间:2024/05/17 21:16
#include <iostream>#include <cstdio>#include <queue>#include <algorithm>#include <cstring>#include <cstdlib>#define N 10using namespace std;int x1,y1,x2,y2;int sum;int dx[8]={1,2,2,1,-1,-2,-2,-1};int dy[8]={2,1,-1,-2,-2,-1,1,2};queue<int>xx;queue<int>yy;bool map[N][N];int l[N][N];bool inmap(int x,int y){return (x<=8&&y<=8&&x>0&&y>0);//判断是否越界 }void bfs(int x,int y){for(int k=0;k<8;k++){if(inmap(x+dx[k],y+dy[k])&&!map[x+dx[k]][y+dy[k]]){map[x+dx[k]][y+dy[k]]=true;l[x+dx[k]][y+dy[k]]=l[x][y]+1;xx.push(x+dx[k]);yy.push(y+dy[k]);if(x+dx[k]==x2&&y+dy[k]==y2){sum=l[x+dx[k]][y+dy[k]];return ;}}}if(!xx.empty()){xx.pop();yy.pop();}if(!xx.empty()){bfs(xx.front(),yy.front());}}int main(){char s[10];while(gets(s))//特殊输入 {sum=0;x1 = (int)s[0] - 96; y1 = (int)s[1] - 48; x2 = (int)s[3] - 96; y2 = (int)s[4] - 48; while(!xx.empty()) { xx.pop(); yy.pop(); } memset(map,false,sizeof(map)); memset(l,0,sizeof(l)); xx.push(x1); yy.push(y1); map[x1][y1]=true; l[x1][y1]=0; bfs(x1,y1); cout <<"To get from "<<s[0]<<y1<<" to "<<s[3]<<y2<<" takes "<<sum<<" knight moves."<< endl;}return 0;}
0 0
- BFS POJ2243- Dario
- poj2243 Knight Moves (BFS)
- POJ2243 简单BFS
- POJ2243 A*算法BFS
- 1poj2243(bfs)
- poj2243~双向bfs
- poj2243 hdu 1372 bfs
- POJ2243 Knight Moves(BFS)
- poj2243-Knight Moves-水bfs
- poj2243--骑士骑马--bfs算法
- poj2243 && hdu1372 Knight Moves(BFS)
- POJ2243 Knight moves (BFS求最短路)
- POJ2243
- poj2243
- poj2243
- poj2243
- poj2243
- poj2243 跳马问题,bfs一下就可以了。
- 获取baidu翻译真人发音
- 推测式提问,先“复述你对别人的话语理解”
- Java 标准日志工具 Log4j 的使用(附源代码)
- 【树状数组(三维)】hdu 3584 Cube
- LeetCode OJ:String to Integer (atoi)
- BFS POJ2243- Dario
- LeetCode OJ:Reverse Integer
- centos 下 boost1.55 编译和安装
- ODBC-C语言连接数据库(SQL Server 2000)(上)
- jQuery操作Dom
- android广播机制(上)
- 解决MAC打开不明软件问题,如【打不开“FreeMind.app”,因为它来自身份不明的开发者。 】
- cvThreshold用法(opencv参考手册)
- Ubuntu install cf cli