HDU<1372>/bfs
来源:互联网 发布:卫生间地面材料 知乎 编辑:程序博客网 时间:2024/05/07 13:03
题目连接
简单bfs搜索
#include <set>#include <map>#include <cmath>#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef pair<int, int> pa;typedef long long LL;int dir[8][2]={2,1,2,-1,-2,1,-2,-1,1,2,1,-2,-1,2,-1,-2};struct node{ int x; int y; int step;};int vis[10][10];//标记数组int st,sd,et,ed;queue<node>que;string c1,c2;void init(){ for(int i=0;i<=8;i++) for(int j=0;j<=8;j++) vis[i][j]=0;}void dfs(){ node now,next; now.x=st; now.y=sd; vis[st][sd]=1; now.step=0; while(!que.empty()) que.pop(); que.push(now); while(!que.empty()) { now=que.front(); que.pop(); if(now.x==et&&now.y==ed) { cout<<"To get from "<<c1<<" to "<<c2<<" takes "<<now.step<<" knight moves."<<endl; break; } for(int i=0;i<8;i++) { int X=now.x+dir[i][0]; int Y=now.y+dir[i][1]; if(X>=1&&X<=8&&Y>=1&&Y<=8&&!vis[X][Y]) { next.x=X; next.y=Y; next.step=now.step+1; vis[X][Y]=1; que.push(next); } } }}int main (){ while(cin>>c1>>c2) { init(); st=c1[0]-'a'+1; sd=c1[1]-'1'+1; et=c2[0]-'a'+1; ed=c2[1]-'1'+1; dfs(); } return 0;}
0 0
- HDU 1372 (BFS)
- HDU 1372 BFS
- HDU 1372 BFS
- hdu 1372 简单bfs
- poj2243 hdu 1372 bfs
- hdu 1372 bfs
- HDU 1372(BFS)
- HDU 1372 BFS
- HDU<1372>/bfs
- hdu 1372 BFS
- HDU 1372 骑士漫游 bfs
- hdu 1372 bfs Knight Moves
- HDU-1372 Knight Moves (BFS)
- HDU-1372 Knight Moves (BFS)
- HDU 1372 Knight Moves【BFS】
- HDU 1372 Knight Moves(BFS)
- HDU 1372--Knight Moves【BFS】
- hdu 1372 Knight Moves(bfs)
- 我的第一个C程序Helloc
- poj 2540
- css3属性突然transform详解
- 如何在ipython或python中使用Spark
- 湖南省第十届大学生计算机程序设计竞赛第五题(模拟题)
- HDU<1372>/bfs
- LintCode:跳跃游戏 II
- 【C语言】模拟实现strcpy、strcat、strcmp函数
- PyGobject(六十)布局容器之TextView
- 如何给mysql共享表空间扩容
- 设计模式之观察者模式
- javascript循环计时器
- H5学习之13 head标签 (meta标签等)
- 统计目录中的文件