hud 1241(BFS)
来源:互联网 发布:滴滴司机 知乎 编辑:程序博客网 时间:2024/06/05 05:34
一道简单的搜索题,本题我用的是广搜写的,深搜当然也可以...
#include <iostream>#include <queue>#include<string.h>using namespace std;int m,n;char map[105][105];int dir[][2]={{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};struct st{int x,y;st(int m=0,int n=0){x=m;y=n;}};void bfs(int x,int y){queue<st> Q;st fir;Q.push(st(x,y));map[x][y]='*';while(!Q.empty()){fir=Q.front();for(int i=0;i<8;i++){int tx=fir.x+dir[i][0],ty=fir.y+dir[i][1];if(map[tx][ty]=='@'){Q.push(st(tx,ty));map[tx][ty]='*';}} Q.pop();}}int main(){while(scanf("%d%d",&n,&m)&&(n||m)){int num=0;memset(map,0,sizeof(map));for(int i=1;i<=n;i++)scanf("%s",map[i]+1);for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){if(map[i][j]=='@'){num++;bfs(i,j);}}printf("%d\n",num);}}
- hud 1241(BFS)
- HUD 1253【BFS】
- HUD 1175 bfs广度搜索
- hud 1372 Knight Moves【bfs】
- Nyoj 523&&Hud 1253 亡命逃窜[Bfs]
- 题解:HUD 2102:A计划 (BFS)
- hud 1010 走迷宫 搜索—bfs
- hud 1241 Oil Deposits
- HUD
- HUD 1548 BFS 换了一种实现方式
- bfs专题之HUD 1429 胜利大逃亡(续)
- Hud 1026 Ignatius and the Princess I[Bfs]
- Oil Deposits (dfs)【HUD】-1241
- HUD 1241 搜索 三维深搜
- 【HUD 杭电 1241】Oil Deposits
- HUD 1000
- HUD 1033
- HUD 4038
- PHP编程之HTML(表格标签)
- 全局变量管理器
- css在线压缩工具!
- 虚拟机里实现ubuntu共享windows文件夹
- 《STL源码剖析》-- stl_construct.h
- hud 1241(BFS)
- 第一篇C语言BLOG
- bash 中的函数参数和返回值
- php连接mssql
- bash中的数组遍历
- C#学习笔记
- bash中的for循环
- awk中使用bash中定义的变量
- body标签