poj 1562 简单的BFS搜索
来源:互联网 发布:最新一手收藏品数据 编辑:程序博客网 时间:2024/05/16 15:05
对于个给出的图,用一个整型的二维数组代表有无石油,然后循环这个二维数组,如发现存在石油,则以这个方格为起始结点进行深搜,如发现石油就标记为-1,然后继续遍历这个二维数组,直至找到下一个有石油的方格,找到一个计数加1。最后的计数即为所求的石油的方块数。
#include<algorithm>#include<iostream>#include<cstdio>#include<cstdlib>using namespace std;char map[100][100];int vis[100][100];int m, n; int op[8][2]={{-1,-1},{-1,0},{1,0},{0,1},{1,1},{-1,1},{1,-1},{0,-1}}; void search(int x, int y) { vis[x][y]=-1; for(int i=0; i<8; i++) if((x+op[i][0]>=0)&&(x+op[i][0]<m)&&(y+op[i][1]>=0)&&(y+op[i][1]<n)&&(vis[x+op[i][0]][y+op[i][1]]!=-1) && map[x+op[i][0]][y+op[i][1]]=='@') search(x+op[i][0],y+op[i][1]); }int main(){ int i, j, sum; while(scanf("%d %d",&m, &n)&&m) { sum = 0; for(i=0; i<m; i++) for(j=0; j<n; j++) cin>>map[i][j]; memset(vis,0,sizeof(vis)); for(i=0; i<m; i++) for(j=0; j<n; j++) if(vis[i][j]!=-1&&map[i][j]=='@') { sum++; search(i,j); } printf("%d\n",sum); } system("pause"); return 0;}
- poj 1562 简单的BFS搜索
- poj 2251 简单搜索bfs
- poj 3278 简单搜索bfs
- POJ 3126-Prime Path 简单搜索 BFS
- POJ 3414-Pots 简单搜索 BFS
- 搜索练习6/poj.org/problem3278 /Catch That Cow/简单的bfs模板
- poj 3414 搜索BFS
- poj 2243 BFS搜索
- POJ 1426 Find The Multiple(简单搜索bfs)
- hdu1175简单的搜索(bfs法)
- 简单bfs 广度搜索
- poj 1979 简单的搜索
- poj 3278 简单的搜索
- poj 2488 简单的搜索
- poj 2251 逃出牢笼,简单的bfs
- BFS专攻:POJ 3278 (三个方向的简单BFS)
- poj 3626 简单bfs
- poj 3126 简单bfs
- Linux串口编程详解
- mock测试
- quartz集群完整应用实例
- Ajax模拟留言
- Java多线程:线程同步——实验1
- poj 1562 简单的BFS搜索
- Android学电子相册
- Android之完美退出方法(2.1-2.2-2.3SDK版本均测试通过)
- linux2.6.x的配置文件kconfig语法
- 深入研究java.lang.Class类
- MMU的作用
- Inversion of Control
- 我的山寨生涯(4)
- Java多线程:线程同步——实验2