poj - 2386 Lake Counting && hdoj -1241Oil Deposits (简单dfs)
2015-05-20 21:00
435 查看
http://poj.org/problem?id=2386
http://acm.hdu.edu.cn/showproblem.php?pid=1241
求有多少个连通子图。复杂度都是O(n*m)。
http://acm.hdu.edu.cn/showproblem.php?pid=1241
求有多少个连通子图。复杂度都是O(n*m)。
#include <cstdio> char filed[110][110]; int n,m; void dfs(int x,int y) { for(int i=-1;i<=1;i++) for(int j=-1;j<=1;j++) //循环遍历8个方向 { int xx=x+i,yy=y+j; if(xx>=0&&xx<n&&yy>=0&&yy<m&&filed[xx][yy]=='W') { filed[xx][yy]='.'; dfs(xx,yy); } } return; } int main() { //freopen("a.txt","r",stdin); while(~scanf("%d%d",&n,&m)) { getchar(); int count=0; for(int i=0;i<n;i++) scanf("%s",filed[i]); for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(filed[i][j]=='W') { dfs(i,j); count++; } printf("%d\n",count); } return 0; }
相关文章推荐
- DFS:Lake Counting POJ 2386
- 【poj】2386 Lake Counting bfs||dfs
- POJ - 2386 Lake Counting DFS
- poj-1979 && hdoj - 1312 Red and Black (简单dfs)
- POJ 2386 Lake Counting DFS初步
- POJ—2386—Lake Counting—【DFS】
- POJ 2386 Lake Counting dfs
- POJ 2386 lake counting DFS
- POJ 2396 Lake Counting(简单dfs)
- POJ 2386 Lake Counting DFS
- DFS---Lake Counting&& Oil Deposits&&迷宫问题
- POJ 2386 Lake Count 简单的递归深搜
- poj 3984 迷宫问题【BFS && DFS】【简单】
- POJ 2386 Lake Counting G++
- POJ 2386 Lake Counting 简单的DFS搜索
- POJ 2386 Lake Counting 简单的DFS搜索
- POJ 2386 Lake Counting DPS解法
- hdoj 1455 && nyoj 293 && poj 1110 Sticks 【DFS + 剪枝 + 剪枝 + 剪枝 + 。。。+ 剪枝】
- POJ-2386-Lake_Counting
- hdoj - 1258 Sum It Up && hdoj - 1016 Prime Ring Problem (简单dfs)