poj2386 Lake Counting【DFS】
来源:互联网 发布:sha1算法 编辑:程序博客网 时间:2024/04/28 00:29
题目链接:http://poj.org/problem?id=2386
题意:和油田问题是一样的
解析:不解释,直接起手就是一个dfs
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;const int maxn = 105;int dx[] = {0,1,-1,0,-1,1,-1,1};int dy[] = {1,0,0,-1,-1,1,1,-1};char mapple[maxn][maxn];int vis[maxn][maxn];int n,m;void dfs(int x,int y){ for(int i=0;i<8;i++) { int tx = x + dx[i]; int ty = y + dy[i]; if(tx<0 || ty<0 || tx>=n || ty>=m) continue; if(mapple[tx][ty]=='.' || vis[tx][ty]) continue; vis[tx][ty] = 1; dfs(tx,ty); }}int main(void){ scanf("%d %d",&n,&m); for(int i=0;i<n;i++) scanf("%s",mapple[i]); memset(vis,0,sizeof(vis)); int ans = 0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(mapple[i][j]=='W' && !vis[i][j]) { ans++; vis[i][j]=1; dfs(i,j); } } } printf("%d\n",ans); return 0;}
0 0
- POJ2386:Lake Counting(DFS)
- poj2386 Lake Counting DFS
- POJ2386 Lake Counting(DFS)
- POJ2386 Lake Counting 【DFS】
- POJ2386 Lake Counting (dfs)
- POJ2386 Lake Counting(dfs)
- poj2386 Lake Counting【DFS】
- POJ2386 Lake Counting (DFS)
- POJ2386 Lake Counting 图DFS
- POJ2386:Lake Counting(dfs)
- POJ2386 Lake Counting简单dfs
- poj2386 Lake Counting(简单DFS)
- POJ2386 Lake Counting 图遍历/DFS
- POJ2386 Lake Counting
- poj2386 Lake Counting
- poj2386 Lake Counting
- poj2386 Lake Counting
- Lake Counting--poj2386
- C#语言和数据库技术基础
- lightoj 1234
- 最长单调递增子序列的三种解法
- HDU 6016 Count the Sheep
- 测试代码的执行时间:%time和%timeit
- poj2386 Lake Counting【DFS】
- 创建对象的方式(1)
- 文章标题
- Promblem 442 Find All Duplicates in an Array
- MySQL高级-笔记
- weex官方demo weex-hackernews代码解读(1)
- 基本数据类型
- 最短路径—Dijkstra算法和Floyd算法
- 年薪5w和50w的人,区别到底在哪?