poj 2386 Lake Counting(深搜)
来源:互联网 发布:阿里云学生服务器 编辑:程序博客网 时间:2024/06/07 02:39
题目地址
题目大意:有一个大小为N*M的园子,雨后积了很多水。八连通的积水被认为是在一起的。请求出园子里共有多少个水洼?(八连通是指相邻的八个方向)
解题思路:找到一个‘W’对其周围也是‘W’的进行深搜,深搜的次数即为八连通的块数
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <algorithm>#include <string>#include <queue>#include <vector>#include <list>#include <stack>#include <map>#include <set>using namespace std;const int maxn = 1000+100;const int dir[8][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};char s[maxn][maxn];int n,m;void dfs(int x,int y){ s[x][y] = '.'; for(int i = 0; i < 8; i++) { int xx = x+dir[i][0]; int yy = y+dir[i][1]; if(xx>=0&&xx<n&&yy>=0&&yy<m&&s[xx][yy]=='W') dfs(xx,yy); } return ;}int main(){ while(scanf("%d%d",&n,&m) != EOF) { getchar(); for(int i = 0; i < n; i++) gets(s[i]); int sum = 0; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) if(s[i][j] == 'W') { dfs(i,j); sum++; } printf("%d\n",sum); } return 0;}
0 0
- poj 2386 Lake Counting(深搜)
- POJ-2386--Lake Counting---DFS(深搜)
- POJ 2386----Lake Counting (深搜)
- poj 2386 (Lake Counting)
- Lake Counting(POJ 2386)
- 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
- 最小风险贝叶斯决策
- Merge Intervals
- Leetcode 18 4Sum
- 8款样式新颖的jQueryCSS3网页菜单
- CentOS 7 运行级别的切换
- poj 2386 Lake Counting(深搜)
- greedy algorithm DEMO
- mac eclipse实用快捷键总结
- Ext.Msg.QUESTION、Ext.Msg.WARNING---ExtJS学习------Ext.Msg.show()学习
- 【Java并发编程实战】-----线程基本概念
- C语言缓冲区(缓存)详解
- MyBatis学习系列六:新增和更新
- C语言常见函数重写
- poj 3468 A Simple Problem with Integers(线段树、延迟更新)