poj 2386 lake counting
来源:互联网 发布:网络保险中介会倒闭吗 编辑:程序博客网 时间:2024/06/05 03:17
(1)类型:深搜
(2)题意:一个大小为N*M的园子,雨后积起了水。八连通的积水被认为是连接在一起的。求园子里总共有多少个水洼。
例如:
* * *
* w*
* ** 此种情况下为八连通情况。
(3)时间复杂度:O(N*M)
(4)代码:
#include<iostream>const int MAX_N=1e2+6;using namespace std;int n,m;char field[MAX_N][MAX_N];void dfs(int x,int y){ field[x][y]='.'; for(int dx=-1;dx<=1;dx++) for(int dy=-1;dy<=1;dy++){ int nx=x+dx,ny=y+dy; if(nx>=0&&nx<n&&ny>=0&&ny<m&&field[nx][ny]=='W')dfs(nx,ny); } return ;}void solve(){ int res=0; for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(field[i][j]=='W'){ dfs(i,j);res++; } cout<<res<<endl;}int main(){ ios::sync_with_stdio(false);cin.tie(0); cin>>n>>m; for(int i=0;i<n;i++) for(int j=0;j<m;j++)cin>>field[i][j]; solve();}
阅读全文
1 0
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ-2386-Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- Poj 2386 Lake Counting
- poj 2386 Lake Counting
- bootstrap Maximum call stack size exceeded
- comma.ai的数据集下载不了
- 解决友盟推送(U-Push)的register不成功,返回错误信息s=-11,s1=accs bindapp error
- Android open source TextView中的文本自动对齐
- Qt+VS "ErrorC1083Cannot open source file: 'GeneratedFiles\Debug\moc_xxx"
- poj 2386 lake counting
- 单机环境搭建kafka
- Fiddle使用
- 【bzoj1486】【[HNOI2009]梦幻布丁】启发式链表合并(详解)
- wampserver 的安装和使用
- 腾讯云重装为centos6.7 x64 后重新挂载原NTFS云硬盘
- 目标完美程序员!你看好编码规范吗?
- 04.类的初始化
- 泊松分布