HDOJ 2612 bfs
来源:互联网 发布:淘宝买家自动评价软件 编辑:程序博客网 时间:2024/06/06 03:15
#include"queue"#include"stdio.h"#include"iostream"using namespace std;const int N=205;const int inf=99999;struct node{ int x,y,step;};inline int min(int a,int b){ return a>b?b:a;}char map[N][N];int visit[N][N];int m,n;int b[N][N];int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};void bfs(node s){ queue<node>Q; node q; s.step=0; Q.push(s); visit[s.x][s.y]=1; while(!Q.empty()) { q=Q.front(); Q.pop(); if(map[q.x][q.y]=='@') b[q.x][q.y]+=q.step; for(int i=0;i<4;i++) { s.x=q.x+dir[i][0]; s.y=q.y+dir[i][1]; if(s.x>=0&&s.x<n&&s.y>=0&&s.y<m&&visit[s.x][s.y]==0&&map[s.x][s.y]!='#') { visit[s.x][s.y]=1; s.step=q.step+1; Q.push(s); } } }}int main(){ //freopen("a.txt","r",stdin); while(cin>>n>>m) { node s1,s2; memset(map,0,sizeof(map)); memset(b,0,sizeof(b)); memset(visit,0,sizeof(visit)); int i,j; for(i=0;i<n;i++) for(j=0;j<m;j++) { cin>>map[i][j]; if(map[i][j]=='Y') { s1.x=i; s1.y=j; } if(map[i][j]=='M') { s2.x=i; s2.y=j; } } bfs(s1); memset(visit,0,sizeof(visit)); bfs(s2); int Min=inf; for(i=0;i<n;i++) { for(j=0;j<m;j++) if(b[i][j]!=0) Min=min(Min,b[i][j]); } cout<<Min*11<<endl;; } return 0;}
0 0
- HDOJ 2612 bfs
- hdoj 2612 Find a way (BFS)
- hdoj-2612-find a way-双向BFS
- HDOJ 2612 Find a way【BFS】
- HDOJ 2612 Find a way (双向BFS)
- hdoj 1242 Rescue(bfs)
- HDOJ 1072 Nightmare (bfs)
- HDOJ 2364 Escape (bfs)
- hdoj 2364 Escape(BFS)
- HDOJ 1072 Nightmare bfs
- Hdoj 1424 Rescue 【BFS】
- hdoj 1242 Rescue (BFS)
- hdoj Asteroids! (BFS)
- hdoj 1242 Rescue [BFS]
- hdoj 5040 bfs
- hdoj 1072 Nightmare 【bfs】
- HDOJ 1242 Rescue【BFS】
- hdoj 5335 bfs
- mac 打开开发者模式
- android KTV 开发(一)自定义videoView 实现视频大小自由缩放、全屏与预览
- OKHttp 请求库
- Poj 3320 acm 数据结构 哈希表入门
- PageRank算法简介及Map-Reduce实现
- HDOJ 2612 bfs
- GPU 原理解密(一)画个三角形居然这么难
- blkid命令 获取文件系统类型、UUID
- Java线程同步中关键字synchronized详述
- win配置mysql 5.7 zip版
- 数据库-Oracle中的聚簇
- IP地址类
- http错误404.17 错误代码 0x80070032 问题解决
- C++ 通过RegEnumKeyEx枚举的问题