hdu - 2645 find the nearest station (bfs水)
http://acm.hdu.edu.cn/showproblem.php?pid=2645
找出每个点到距离最近的车站的距离。
直接bfs就好。
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
int n,m;
int maze[][],dis[][],vis[][];
int dir[][]={-,,,,,,,-};
struct point
{
int x,y,step;
}; int bfs(int a,int b)
{
// printf("%d %d\n",a,b);
memset(vis,,sizeof(vis));
queue<point>que;
point s;
s.x=a;s.y=b;s.step=;
que.push(s);
vis[s.x][s.y]=;
while(!que.empty())
{
point e=que.front();que.pop();
// printf("%d %d %d\n",e.x,e.y,e.step);
if(maze[e.x][e.y]) return e.step;
for(int i=;i<;i++)
{
s.x=e.x+dir[i][];
s.y=e.y+dir[i][];
if(!vis[s.x][s.y]&&s.x>=&&s.x<n&&s.y>=&&s.y<m)
{
vis[s.x][s.y]=;
s.step=e.step+;
que.push(s);
}
}
}
} int main()
{
// freopen("a.txt","r",stdin);
char s[];
while(~scanf("%d%d",&n,&m))
{
for(int i=;i<n;i++)
{
scanf("%s",s);
for(int j=;j<m;j++)
{
maze[i][j]=s[j]-'';
//printf("%d\n",maze[i][j]);
}
}
memset(dis,,sizeof(dis));
for(int i=;i<n;i++)
for(int j=;j<m;j++)
if(!maze[i][j])
dis[i][j]=bfs(i,j);
for(int i=;i<n;i++)
{
for(int j=;j<m-;j++)
printf("%d ",dis[i][j]);
printf("%d\n",dis[i][m-]);
}
}
return ;
}
hdu - 2645 find the nearest station (bfs水)的更多相关文章
- hdu 2645 find the nearest station
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2645 find the nearest station Description Since dande ...
- 【HDOJ】2645 find the nearest station
裸BFS. /* 2645 */ #include <iostream> #include <queue> #include <cstdio> #include & ...
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- HDU.2612 Find a way (BFS)
HDU.2612 Find a way (BFS) 题意分析 圣诞节要到了,坤神和瑞瑞这对基佬想一起去召唤师大峡谷开开车.百度地图一下,发现周围的召唤师大峡谷还不少,这对基佬纠结着,该去哪一个...坤 ...
- HDU 6386 Age of Moyu 【BFS + 优先队列优化】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6386 Age of Moyu Time Limit: 5000/2500 MS (Java/Others ...
- nyoj--523--亡命逃窜(BFS水题)
亡命逃窜 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 从前有个叫hck的骑士,为了救我们美丽的公主,潜入魔王的老巢,够英雄吧.不过英雄不是这么好当的.这个可怜的娃被魔 ...
- hdu 2393:Higher Math(计算几何,水题)
Higher Math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu1240 bfs 水题
原题链接 思路:水题,直接搜 #include "map" #include "queue" #include "math.h" #incl ...
随机推荐
- 在spring boot 中使用itext和itextrender生成pdf文件
转载请注明出处 https://www.cnblogs.com/majianming/p/9539376.html 项目中需要对订单生成pdf文件,在第一版本其实已经有了比较满意的pdf文档,但是还是 ...
- SpringMVC -- 必知必会
SpringMVC基于模型--视图--控制器(Model-View-Controller,MVC)模式实现,属于SpringFrameWork的后续产品,已经融合在SpringWebFlow里面.它通 ...
- java设计模式之代理模式 ,以及和java 回调机制的区别
java 代理模式就是: 将自己要做的事交给别人去做(这个别人就是代理者,自己就是被代理者),为什么自己能做的要交给别人去做了?假如一个小学生小明,现在要写作业,但是又想玩游戏,他更想玩游戏,并且不想 ...
- Android Studio 打包APK时,出现3个或多个APK
Android Studio 打包APK时,原来只会出现一个apk,结果现在出现3个apk,仔细检查了一下项目文件发现: Android Studio 的 buid.gradle文件里有个配置项被更改 ...
- webpack3整理(第二节/满三节)
消除未使用的CSS:安装PurifyCSS-webpack插件 cnpm i purifycss-webpack purify-css -D const glob = require('glob'); ...
- swift class extension 与继承
1.扩展中无法继承重写已有函数,不能添加函数. Extensions can add new functionality to a type, but they cannot override exi ...
- js 删除数组中某一项的几种方法总结
第一种:改变原数组 借用原生数组方法:splice(index,len,[item]) 剪接 借用原生对象方法:delete array[index] + array.slice(0, index) ...
- 导出网页表格数据为Excel文件的前端解决方案
在工作中,我们有时会遇到这样的需求,比如:要把页面的表格数据导出为Excel文件.在此记录下自己用的解决方法.代码如下: function tableToExcel(data){ //要导出的数据,t ...
- 小a与"204"(牛客)
原题 公式 中间数字与变量之间乘号bug省略可能看着有点别扭例如8x2为8*x2 首先设扫一遍后0的个数为x0 2的个数为x2 4的个数为x4 ①如果x0=x4 ans=32*x4+4 ②如果x0&g ...
- ubuntu server 12.04.4安装配置
这里讲