POJ 2386 Lake Counting DFS水水
http://poj.org/problem?id=2386
题目大意:
有一个大小为N*M的园子,雨后积起了水。八连通的积水被认为是连接在一起的。请求出院子里共有多少水洼?
思路:
水题~直接DFS,DFS过程把途中表示水洼的W改为‘.',看DFS了几次即可。
- #include<cstdio>
- #include<cstring>
- const int MAXN=100+10;
- char map[MAXN][MAXN];
- int n,m;
- void dfs(int x,int y)
- {
- if(map[x][y]=='.')
- return ;
- map[x][y]='.';
- dfs(x+1,y+1);
- dfs(x,y+1);
- dfs(x-1,y+1);
- dfs(x-1,y);
- dfs(x-1,y-1);
- dfs(x,y-1);
- dfs(x+1,y-1);
- dfs(x+1,y);
- }
- int main()
- {
- while(~scanf("%d%d",&n,&m))
- {
- for(int i=1;i<=n;i++)
- scanf("%s",map[i]+1);
- for(int i=0;i<=n+1;i++)
- map[i][0]=map[i][m+1]='.';
- for(int i=0;i<=m+1;i++)
- map[0][i]=map[n+1][i]='.';
- int ans=0;
- for(int i=0;i<=n+1;i++)
- {
- for(int j=0;j<=m+1;j++)
- {
- if(map[i][j]=='W') {
- ans++;
- dfs(i,j);
- }
- }
- }
- printf("%d\n",ans);
- }
- return 0;
- }
POJ 2386 Lake Counting DFS水水的更多相关文章
- [POJ 2386] Lake Counting(DFS)
Lake Counting Description Due to recent rains, water has pooled in various places in Farmer John's f ...
- POJ:2386 Lake Counting(dfs)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40370 Accepted: 20015 D ...
- poj 2386:Lake Counting(简单DFS深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18201 Accepted: 9192 De ...
- POJ 2386 Lake Counting(深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17917 Accepted: 906 ...
- POJ 2386 Lake Counting
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28966 Accepted: 14505 D ...
- POJ 2386 Lake Counting(搜索联通块)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48370 Accepted: 23775 Descr ...
- POJ 2386 Lake Counting 八方向棋盘搜索
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 53301 Accepted: 26062 D ...
- poj - 2386 Lake Counting && hdoj -1241Oil Deposits (简单dfs)
http://poj.org/problem?id=2386 http://acm.hdu.edu.cn/showproblem.php?pid=1241 求有多少个连通子图.复杂度都是O(n*m). ...
- POJ 2386——Lake Counting(DFS)
链接:http://poj.org/problem?id=2386 题解 #include<cstdio> #include<stack> using namespace st ...
随机推荐
- Annotation中Result的params属性
这个属性只有在重定向时有用,而转发时不会设置参数. 如: @Results({ @Result(name="success", location="page", ...
- OCP-1Z0-051-题目解析-第26题
26. Which is the valid CREATE TABLE statement? A. CREATE TABLE emp9$# (emp_no NUMBER (4)); B. CRE ...
- [Java开发之路](9)对象序列化与反序列化
1. 对象序列化 当你创建对象时.仅仅要你须要.它会一直存在,可是程序终止时,不管何时它都不会继续存在.虽然这样做是很有意义的,可是在某些情况下.假设程序不执行时扔能存在而且保存其信息,那将对我们很实 ...
- 归并排序_分治算法 (白书P226)
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int a ...
- Nginx安装以及配置
安装编译工具及库文件 1 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 安装 PCRE 下载 PC ...
- jq ---- 实现浏览器全屏
// 点击进入全屏 方法. var fullscreen=function(){ elem=document.body; if(elem.webkitRequestFullScreen){ elem. ...
- 洛谷P2115 [USACO14MAR]破坏Sabotage
题目描述 Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer John's milking equipmen ...
- HDU 2633 Getting Driving License(模拟)
Getting Driving License Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- Input/output subsystem having an integrated advanced programmable interrupt controller for use in a personal computer
A computer system is described having one or more host processors, a host chipset and an input/outpu ...
- Centos6.4安装opennebula
Centos6.4安装opennebula #安装163源 http://mirrors.163.com/.help/CentOS6-Base-163.repo #安装epel源 wget http: ...