1751: [Usaco2005 qua]Lake Counting

Time Limit: 5 Sec  Memory Limit: 64 MB

Submit: 168  Solved: 130

[Submit][Status]

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



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<iostream>
using namespace std;
const int mx[8]={1,1,1,0,0,-1,-1,-1};
const int my[8]={1,0,-1,1,-1,1,0,-1};
int n,m,ans;
int map[110][110];
void dfs(int x,int y)
{
map[x][y]=0;
for (int k=0;k<8;k++)
{
int nx=mx[k]+x;
int ny=my[k]+y;
if (map[nx][ny]) dfs(nx,ny);
}
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{
char ch;
cin>>ch;
if (ch=='W')map[i][j]=1;
}
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
if(map[i][j]){dfs(i,j);ans++;}
printf("%d",ans);
}

bzoj1751 [Usaco2005 qua]Lake Counting的更多相关文章

  1. 1751: [Usaco2005 qua]Lake Counting

    1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 190  Solved: 150[Su ...

  2. POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)

    来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS   Memory Limit: 65536 ...

  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. BZOJ1754: [Usaco2005 qua]Bull Math

    1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 374  Solved: 227[Submit ...

  6. BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁

    2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 56  Solved: 16[S ...

  7. BZOJ 3385: [Usaco2004 Nov]Lake Counting 数池塘

    题目 3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec  Memory Limit: 128 MB Description     农夫 ...

  8. 1755: [Usaco2005 qua]Bank Interest

    1755: [Usaco2005 qua]Bank Interest Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 187  Solved: 162[Su ...

  9. 1753: [Usaco2005 qua]Who's in the Middle

    1753: [Usaco2005 qua]Who's in the Middle Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 290  Solved:  ...

随机推荐

  1. EBS导出键弹性域

    select gl_flexfields_pkg.get_description_sql(gcc.chart_of_accounts_id, 1, gcc.segment1) || '-' || gl ...

  2. 用Nginx实现Session共享的均衡负载

    前言 大学三年多,也做个几个网站和APP后端,老是被人问到,如果用户多了服务器会不会挂,总是很尴尬的回答:“哈哈,我们的用户还少,到了服务器撑不住的时候,估计都上市了吧”.说是这么说,但是对于有强迫症 ...

  3. HDU4514(非连通图的环判断与图中最长链)

    题目:设计风景线 题意:给定一个无向图,图可能是非连通的,如果图中存在环,就输出YES,否则就输出图中最长链的长度. 分析:首先我们得考虑这是一个无向图,而且有可能是非连通的,那么就不能直接像求树那样 ...

  4. 设置MATLAB中figure的背景为白色

    matlab的图形窗口每次背景都是灰色的,而我希望每次都是白色的背景,方便用图: 每次总是需要添加figure('color','w');或者figure('color',[1 1 1])或者set( ...

  5. 使用css框架的优缺点

    使用css框架的优点 1.加速开发 CSS框架提供通用的代码(如reset,和移动端开发的一些常用设置)和许多丰富的UI组件样式——因此我们不需要从头开始写. 2.无兼容性烦恼 CSS框架解决了各个浏 ...

  6. GitHub上可能用到的开源

    AGi18n :https://github.com/angelolloqui/AGi18n 可以简单地本地化你的iOS app,从代码和XIB文件中提取文本转化成可本地化的字符串,且不会改变XIB文 ...

  7. [Regex Expression] Use Shorthand to Find Common Sets of Characters

    In this lesson we'll learn shorthands for common character classes as well as their negated forms. v ...

  8. C-二维数组,多维数组

    -----二维数组      ->在数组定义当中,行数和列数需要用常量定义      ->在定义的时候如果没有数值进行填充,则补零      ->第一个数是行,第二个数是列     ...

  9. VCS仿真生成vpd文件(verilog)

    VCS仿真生成vpd文件(verilog) 一.环境与文件 Linux平台  csh环境 VCS 64bit 代码文件请参考<一个简单的Verilog计数器模型> 二.开始仿真 1.com ...

  10. 【转】iOS开发24:使用SQLite3存储和读取数据

    转自:http://my.oschina.net/plumsoft/blog/57626 SQLite3是嵌入在iOS中的关系型数据库,对于存储大规模的数据很有效.SQLite3使得不必将每个对象都加 ...