Lake Counting
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 16802   Accepted: 8523

Description

Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer John would like to figure
out how many ponds have formed in his field. A pond is a connected set of squares with water in them, where a square is considered adjacent to all eight of its neighbors. 



Given a diagram of Farmer John's field, determine how many ponds he has.

Input

* Line 1: Two space-separated integers: N and M 



* Lines 2..N+1: M characters per line representing one row of Farmer John's field. Each character is either 'W' or '.'. The characters do not have spaces between them.

Output

* Line 1: The number of ponds in Farmer John's field.

Sample Input

10 12
W........WW.
.WWW.....WWW
....WW...WW.
.........WW.
.........W..
..W......W..
.W.W.....WW.
W.W.W.....W.
.W.W......W.
..W.......W.

Sample Output

3

题目如上:
AC代码如下:
#include<iostream>
#include<stdio.h> #define Max 105
using namespace std; char f[Max][Max];
int N ,M;
void DFS(int x,int y)
{
f[x][y] = '.';
for(int dx = -1; dx <= 1; dx++)
for(int dy = -1; dy <= 1; dy++)
{
int nx, ny;
nx = x + dx; ny = y + dy;
if(nx < N&& ny < M&& nx >= 0&& ny >= 0&&f[nx][ny] == 'W') DFS(nx,ny);
} return ;
}
int main()
{
int res = 0,i,j;
cin>>N;
cin>>M; for(i = 0; i < N; i++)
scanf("%s",&f[i]); for(int i = 0; i < N; i++)
for(int j = 0; j < M; j++)
if(f[i][j] == 'W')
{
DFS(i,j);
res++;
}
printf("%d\n",res);
}

【存在的问题】1、脑残地把坐标轴坐标和矩阵的坐标对应起来了;

           2、解决了以上问题后程序还是在傲娇地RE,原来还是脑残地把“=”敲成“==”了;
            再后来程序还傲娇地WA了,于是           
           3、经大湿的指点把原输入
              for(i = 0; i < N; i++)
                for(j = 0; j < M; j++)
                   scanf("%c",&f[i][j]);
             换成了
               for(i = 0; i < N; i++)
                  scanf("%s", &f[i]);
              蓝后就AC了~~o(≧v≦)o~~
              原因就是%c输入把换行符给吃掉了~~蓝后造成了移位。。。。
              ORZ。。。。

【首先膜拜大湿】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水水

    http://poj.org/problem?id=2386 题目大意: 有一个大小为N*M的园子,雨后积起了水.八连通的积水被认为是连接在一起的.请求出院子里共有多少水洼? 思路: 水题~直接DFS ...

  3. POJ 2386 Lake Counting(深搜)

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

  4. POJ 2386 Lake Counting

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

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

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

  6. POJ:2386 Lake Counting(dfs)

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

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

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

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

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

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

  10. POJ 2386——Lake Counting(DFS)

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

随机推荐

  1. NYOJ-21 三个水杯 AC 分类: NYOJ 2014-02-08 11:35 174人阅读 评论(0) 收藏

    人生中第一个AC的广搜题目,喵呜,C++的STL果真不错, #include<stdio.h> #include<queue> #include<string.h> ...

  2. c++取小数整数部分

    #include<math.h> double ceil(double x) //向上取整 double floor(double x) //向下取整 向上取整,取比x大的第一个整数值向下 ...

  3. JavaScript之四种继承方式讲解

    在Javascript中,所有开发者定义的类都可以作为基类,但出于安全性考虑,本地类和宿主类不能作为基类,这样可以防止公用访问编译过的浏览器级的代码,因为这些代码可以被用于恶意攻击. 选定基类后,就可 ...

  4. DSP中常用的C语言关键字

    const Ø使用:const 数据类型 变量名: Ø作用:优化存储器的分配,表示变量的内容是常数,不会改变. Ø举例:const char tab[1024]={显示数据}; volatile(易变 ...

  5. 移动端页面调试工具——UC浏览器开发者版

    在移动页面的开发中,我们很难像PC端那样很方便的调试,网上也有各种各样的调试方式.但在工作中,我主要还是用chorme自带的模拟器来模拟各种移动设备,但是用久了之后发现毕竟是模拟的,与真机调试还是会有 ...

  6. sql server 时间

    sql server 获取月份天数:1,SELECT 32-DAY(CAST('2015-03-01' as datetime)+32-DAY(CAST('2015-03-01' as datetim ...

  7. Tech Stuff - Mobile Browser ID (User-Agent) Strings

    Tech Stuff - Mobile Browser ID (User-Agent) Strings The non-mobile stuff is here (hint: you get jerk ...

  8. iOS第三方解决键盘遮挡-IQKeyboardManager

    百度云:http://pan.baidu.com/s/1yg5ae githun:https://github.com/hackiftekhar/IQKeyboardManager AppDelega ...

  9. LoaderManager使用详解(二)---了解LoaderManager

    了解LoaderManager   这篇文章将介绍LoaderManager类,这是该系列的第二篇文章. 一:Loaders之前世界 二:了解LoaderManager 三:实现Loaders 四:实 ...

  10. mysql之游标

    游标 行,也不存在每次一行地处理所有行的简单方法(相对于成批地处理它们).有时,需要在检索出来的行中前进或后退一行或多行.这就是使用游标的原因.游标( cursor)是一个存储在MySQL服务器上的数 ...