POJ 2386 Lake Counting-------BFS
来源:互联网 发布:软件专业就业形势 编辑:程序博客网 时间:2024/06/09 18:12
题目地址
//BFS#include <iostream>#include<cstring>#include<queue>#define maxlen 110int mat[maxlen][maxlen];int ans;int dir[8][2]={{0,1},{0,-1},{1,0},{1,-1},{1,1},{-1,0},{-1,1},{-1,-1}};using namespace std;struct node{ int x,y;};void bfs(node s,int m,int n){ queue<node>q; node ne,ol; while(!q.empty()) { q.pop(); } mat[s.x][s.y]=1; q.push(s); while(!q.empty()) { ol=q.front(); q.pop(); for(int l=0; l<8; l++) { ne.x=ol.x+dir[l][0]; ne.y=ol.y+dir[l][1]; if(ne.x>m-1||ne.y>n-1||ne.x<0||ne.y<0||mat[ne.x][ne.y]==1)continue; else { mat[ne.x][ne.y]=1; q.push(ne); } } }}int main(){ int m,n,i,j; char k; node s; memset(mat,0,sizeof(mat)); ans=0; cin >> m >> n; for(i=0; i<m; i++) for(j=0; j<n; j++) { cin >>k; if(k=='.')mat[i][j]=1; } for(i=0; i<m; i++) for(j=0; j<n; j++) { if(mat[i][j]==0) { s.x=i; s.y=j; bfs(s,m,n); ans++; } } cout << ans << endl; return 0;}
- poj 2386 Lake Counting (BFS~)
- POJ 2386 Lake Counting-------BFS
- 【BFS】-POJ-2386-Lake Counting
- Poj 2386 Lake Counting【Bfs】
- 【BFS】poj 2386 Lake Counting
- poj 2386Lake Counting(DFS, BFS)
- poj 2386Lake Counting(BFS搞定)
- poj 2386 Lake Counting 解题报告(BFS)
- POJ 2386 Lake Counting (DFS or BFS)
- POJ 2386 Lake Counting(dfs or bfs)
- POJ 2386 Lake Counting(BFS)
- 【poj】2386 Lake Counting bfs||dfs
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- linux内核实验四实现过程
- call by value 和 call by reference的区别
- CSerialPort类关闭函数
- oracle存储过程,函数,包
- 一个静态分析调用关系的东西
- POJ 2386 Lake Counting-------BFS
- AngularJS 学习 (二)数据绑定
- 内核日志及printk结构浅析
- linux内核实验五实现过程
- ActivityThread-activity启动分析
- “不同的人才”--逍遥游篇2--庄子南华(南怀瑾老师
- ArcGIS在Android的
- 理解矩阵
- hotkey