P1596 [USACO10OCT]湖计数Lake Counting

题目描述

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.

由于近期的降雨,雨水汇集在农民约翰的田地不同的地方。我们用一个NxM(1<=N<=100;1<=M<=100)网格图表示。每个网格中有水('W') 或是旱地('.')。一个网格与其周围的八个网格相连,而一组相连的网格视为一个水坑。约翰想弄清楚他的田地已经形成了多少水坑。给出约翰田地的示意图,确定当中有多少水坑。

输入输出格式

输入格式:

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.

第1行:两个空格隔开的整数:N 和 M 第2行到第N+1行:每行M个字符,每个字符是'W'或'.',它们表示网格图中的一排。字符之间没有空格。

输出格式:

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

一行:水坑的数量

输入输出样例

输入样例#1:

10 12
W........WW.
.WWW.....WWW
....WW...WW.
.........WW.
.........W..
..W......W..
.W.W.....WW.
W.W.W.....W.
.W.W......W.
..W.......W.
输出样例#1:

3

说明

OUTPUT DETAILS: There are three ponds: one in the upper left, one in the lower left, and one along the right side.

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 110
using namespace std;
]={,,,,,-,-,-},yy[]={,-,,,-,,,-};
char ch[N][N];
bool vis[N][N];
int read()
{
    ,f=;char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
void dfs(int x,int y)
{
    ||y<||x>n||y>m||vis[x][y]) return ;
    vis[x][y]=true;
    ;i<;i++)
    {
        if(ch[x+xx[i]][y+yy[i]]=='W')
         dfs(x+xx[i],y+yy[i]);
    }
}
int main()
{
    n=read(),m=read();
    ;i<=n;i++)
     ;j<=m;j++)
      cin>>ch[i][j];
    ;i<=n;i++)
     ;j<=m;j++)
      if(ch[i][j]=='W'&&!vis[i][j])
       ans++,dfs(i,j);
    printf("%d",ans);
}

洛谷——P1596 [USACO10OCT]湖计数Lake Counting的更多相关文章

  1. 洛谷 P1596 [USACO10OCT]湖计数Lake Counting

    题目链接 https://www.luogu.org/problemnew/show/P1596 题目描述 Due to recent rains, water has pooled in vario ...

  2. 洛谷P1596 [USACO10OCT]湖计数Lake Counting

    https://www.luogu.org/problemnew/show/P1596 连通块水题... 大体思路是找到是水坑的坐标然后就开始不断递归,往八个方向搜,把连在一起的都标记一遍直到找不到为 ...

  3. Luogu P1596 [USACO10OCT]湖计数Lake Counting

    题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is repres ...

  4. $P1596 [USACO10OCT]湖计数Lake Counting$

    \(problem\) 其实这题吧\(DFS\)好写一点(大雾 所以就不讲\(DFS\)了 em \(BFS\)的话 主要是 判重. 方向. 队列.(没了吧 至于位置 用两个队列?还是\(pair\) ...

  5. P1596 【[USACO10OCT]湖计数Lake Counting】

    可爱的题面君~~ 个人感觉这题还是很简单的,就是一个完全不加工的找联通块个数 个人解题思路是先读入,然后循环一遍,遇到水就dfs,并把这个w所在的联通块“删除”,并在答案上加一 最后输出答案 具体注释 ...

  6. [USACO10OCT]湖计数Lake Counting 联通块

    题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is repres ...

  7. 洛谷P1144 最短路计数(SPFA)

    To 洛谷.1144 最短路计数 题目描述 给出一个N个顶点M条边的无向无权图,顶点编号为1-N.问从顶点1开始,到其他每个点的最短路有几条. 输入输出格式 输入格式: 输入第一行包含2个正整数N,M ...

  8. 洛谷 1144 最短路计数 bfs

    洛谷1144 最短路计数 传送门 其实这道题目的正解应该是spfa里面加一些处理,,然而,,然而,,既然它是无权图,,那么就直接bfs了,用一个cnt记录一下每一个点的方案数,分几种情况讨论一下转移, ...

  9. 洛谷 P4017 最大食物链计数

    洛谷 P4017 最大食物链计数 洛谷传送门 题目背景 你知道食物链吗?Delia生物考试的时候,数食物链条数的题目全都错了,因为她总是重复数了几条或漏掉了几条.于是她来就来求助你,然而你也不会啊!写 ...

随机推荐

  1. myeclipse 安装svn(subeclipsesite)插件

    (1)到官网下载subeclipsesite,下载最新的版本:http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=224 ...

  2. 一个简单的139邮箱登录脚本--->java-selenium

    import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebE ...

  3. SEO 第三章

    SEO第三章 本次课目标: 1.  掌握关键词的选取方法 2.  掌握关键词的竞争强度分析 3.  掌握关键词的拓展方法 一.关键词的选取 选择关键词的时候可以根据公司网站的定位,围绕公司的主营产品或 ...

  4. 解决异常System.Runtime.Interopservices.COMException RequestLock问题

    工具——导入导出设置,重置调试设置就可以了,这是调试文件的异常

  5. python笔记_magic变量和函数

    前言 先扯一点背景知识 PEP8(Python Enhancement Proposal)是一份python的编码规范,链接:http://www.python.org/dev/peps/pep-00 ...

  6. TensorFlow中屏蔽warning的方法

    问题 使用sudo pip3 install tensorflow安装完CPU版tensorflow后,运行简单的测试程序,出现如下警告: I tensorflow/core/platform/cpu ...

  7. QT_1

    QT概述 1.1 QT 是一个跨平台的C++图形用户界面应用程序框架 1.2 发展史: 1991奇趣科技 1.3 QT 版本:商业版.开源版 1.4 优点: 1.4.1 跨平台 1.4.2 接口简单 ...

  8. The MySQL server is running with the –secure-file-priv

    show variables like '%secure%'; 将文件导出路径更改为查询到的secure-file-priv路径下 select * from table where column = ...

  9. tab bar controller

    下面记一下怎样通过代码的方式为选项卡添加视图. 1.创建一个基于Empty Application的项目 2.创建两个新类,基类选择UIViewController,勾选With XIB for us ...

  10. 记录xerces使用(VS2017 C++)

    1.编译xerces,获得dll文件和lib文件 2.将dll文件和lib文件拷贝到使用xerces的工程目录里面去 3.配置VS2017 C/C++  ->  All Options --&g ...