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水水的更多相关文章

  1. [POJ 2386] Lake Counting(DFS)

    Lake Counting Description Due to recent rains, water has pooled in various places in Farmer John's f ...

  2. POJ:2386 Lake Counting(dfs)

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40370   Accepted: 20015 D ...

  3. poj 2386:Lake Counting(简单DFS深搜)

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18201   Accepted: 9192 De ...

  4. POJ 2386 Lake Counting(深搜)

    Lake Counting Time Limit: 1000MS     Memory Limit: 65536K Total Submissions: 17917     Accepted: 906 ...

  5. POJ 2386 Lake Counting

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28966   Accepted: 14505 D ...

  6. POJ 2386 Lake Counting(搜索联通块)

    Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48370 Accepted: 23775 Descr ...

  7. POJ 2386 Lake Counting 八方向棋盘搜索

    Lake Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 53301   Accepted: 26062 D ...

  8. 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). ...

  9. POJ 2386——Lake Counting(DFS)

    链接:http://poj.org/problem?id=2386 题解 #include<cstdio> #include<stack> using namespace st ...

随机推荐

  1. 洛谷 P3692 [PUB1]夏幻的考试

    P3692 [PUB1]夏幻的考试 题目背景 夏之幻是软件工程系的大神,学校把举办考试的任务交给她了. 题目描述 某大学软工专业要举办一场笔试,学生们要在机读答题卡上填写答案来进行答题.学校把机读卡识 ...

  2. SPSS提示“列表中不同意存在字符串变量”的解决方法

    今天用SPSS对一些数据进行主成分分析,SPSS 19.0进行主成分分析的方法是:分析--降维--因子分析,可是当导入一些变量的时候.就会弹出窗体说"列表中不同意存在字符串变量", ...

  3. 【Struts2】Struts2纯手工安装、配置以及Helloworld,以最新版struts 2.3.20 GA做样例

    很多网上的教程对Struts2的配置.安装弄得不明不白,非常多高手以为小白是什么都懂.很多细节上面的地方没有说明清楚,甚至还有在Maven上面解说的,要知道Struts2跟Maven没有半点的关系.全 ...

  4. 从设计到实现,一步步教你实现Android-Universal-ImageLoader-辅助类

    通过前面几篇博文.我们分析了 AUI 的缓存.工具类.显示与载入这几个方面的代码.今天呢,我们继续研究 AUI 的源代码,学习当中的核心辅助工具类. 希望大家能在里面学到东西哈. Download 要 ...

  5. leetcode: Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  6. 一些优秀的学习网站(Android)

    突然发现自己学习没有总结,从今天开始会持续更新此博文,总结自己的学习情况,也便于自己时常查阅.官方文档就列举了,因为那是必读资料. 一.GitHub部分 1.我的github仓库地址 收藏了我常看的开 ...

  7. git --- ! [rejected] master -> master (non-fast-forward)

    如何解决failed to push some refs to git Administrator@PC-20150110FGWU /K/cocos2d/yc (master) $ git push ...

  8. Android Studio 解决unspecified on project app resolves to an APK archive which is not supported

    出现该问题unspecified on project app resolves to an APK archive which is not supported as a compilation d ...

  9. Kinect 开发 —— 保持视频影像

    相比直接将影像显示出来,如果能将录制到的影像保存到硬盘上就好了.但是,影像录制,是需要一定的技巧,在网上可以看到很多例子演示如何将Kinect获取到的影像以图片的形式保存到本地,前面的博文也介绍了这一 ...

  10. nexus 搭建maven私服

    1. nexus 下载地址 https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.4-03-bundle.tar.g ...