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. 【Python】内置数据类型

    参考资料: http://sebug.net/paper/books/dive-into-python3/native-datatypes.html http://blog.csdn.net/hazi ...

  2. NYOJ-86 找球号(一)AC 分类: NYOJ 2014-02-02 10:45 160人阅读 评论(0) 收藏

    NO.1 单纯的傻傻的代码: #include<stdio.h> long long num[100000005]={0}; int main(){ int n, m, k; scanf( ...

  3. [haoi2009]毛毛虫 树形dp

    这道题细节处理不少,但要AC不难: 设以i节点为根节点的子树能形成的最大的毛毛虫长度为f[i],则f[i]=max(f[j])+i节点的孩子数: 答案需要f最大和次大的两个子树合并,而且若合并的位置不 ...

  4. map初始化定时器

    init_timer(); //各种定时器的初始化 void Map::init_timer() { //auto tf = GetPlug(TimerFactory); auto tf = m_sp ...

  5. 平面最小割—BZOJ 1001

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 很有意思的题目,本来想直接上网络流,但是发现点太多,边太多2333. 直接网络流无法 ...

  6. CountDownLatch,一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待。

    CountDownLatch,一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待. 主要方法 public CountDownLatch(int count); pu ...

  7. Tomcat自动启动脚本

    Tomcat自动启动脚本#!/bin/bash # chkconfig: 2345 10 90 # description: Starts and Stops the Tomcat daemon. T ...

  8. POJ3525 Most Distant Point from the Sea(半平面交)

    给你一个凸多边形,问在里面距离凸边形最远的点. 方法就是二分这个距离,然后将对应的半平面沿着法向平移这个距离,然后判断是否交集为空,为空说明这个距离太大了,否则太小了,二分即可. #pragma wa ...

  9. github and SourceTree初步使用

    1.建立连接(一次就行了) 输入你的github名字 2.创建仓库 3.下载仓库 这个时候打开SouceTree就可以看到之前创的仓库了 点击克隆,创建一个文件夹,讲路径设置好 这时候查看本地列表就会 ...

  10. Twitter注册

    Twitter注册 - (一般分享不了是回调地址不对) 1.打开twitter的官网https://dev.twitter.com,如果还没有注册账号的,需要注册账号,已经注册账号的,请先登录: 2. ...