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. git学习,什么是git?

    什么是 Git? 百度百科显示,Git是 Linux 之父 Linus Trovalds,为管理 Linux 内核代码而建立的,被认为是分布式版本控制工具中的顶级水准.智能.友好.强健.高效. 正如所 ...

  2. WWDC2014 debugging_in_xcode_6 总结

    1.GCD的waiting queue 可以在Xcode左侧的面板中查看. 2.可以对View进行debug类似reveal. 3.查看运行时的对象,对于自定义对象可以实现- (id)debugQui ...

  3. 项目分析(channelid是如果产生的)

    channelid如何生成的 /////////////////////////////////////////////////////////////// // // I_TCPServer.h / ...

  4. API文档管理工具-数据库表结构思考.

    API文档管理工具-数据库表结构思考. PS: 管理工具只是为了方便自己记录API的一些基本信息,方便不同的开发人员 (App Developer, Restful API Developer)之间的 ...

  5. Nodejs Express 4.X 中文API 1--- Application篇

    相关阅读: Express 4.X API 翻译[一] --  Application篇 Express4.XApi 翻译[二] --  Request篇 Express4.XApi 翻译[三] -- ...

  6. 腾讯开源的轻量级CSS3动画库:JX.Animate

          JX.Animate 是由腾讯前端团队 AlloyTeam 推出的一个 CSS3 动画库,通过 JX(腾讯的前端框架)插件的形式提供. Why CSS3 众所周知在支持HTML5的浏览器中 ...

  7. 如何做到尽可能不使用庞大的jQuery

    jQuery 是现在最流行的 JavaScript 工具库. 据统计,目前全世界 57.3% 的网站使用它.也就是说,10 个网站里面,有 6 个使用 jQuery.如果只考察使用工具库的网站,这个比 ...

  8. 对于Linux平台下C语言开发中__sync_函数的认识

      reference:http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html#Atomic-Builtins A built ...

  9. NodeJS异常处理uncaughtException篇

    很多 NodeJS 的开发者在抱怨异常处理太麻烦,我们会通过一些列博客梳理一下NodeJS中常见的异常处理的手段. 和大多数编程语言一样,在 NodeJS 里可以通过throw抛出一个异常: thro ...

  10. POJ 2513 Colored Sticks (离散化+并查集+欧拉通路)

    下面两个写得很清楚了,就不在赘述. http://blog.sina.com.cn/s/blog_5cd4cccf0100apd1.htmlhttp://www.cnblogs.com/lyy2890 ...