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. 齐B小短裙

    女模周蕊微博引关注 火了齐B小短裙毁了干爹[图]_网易新闻中心 齐B小短裙

  2. C++类静态成员的初始化和用法探讨

    一.一般类型的类的静态变量 1.首先看下面的代码: class CTest1 { public: static int m_num1; void printNum(){cout << m_ ...

  3. IEEE论文格式要求

    0.特别提示:本次会议要求各位作者根据审稿意见进行认真修改,然后经过大会主席的检查合格才允许上传IEEE eXpress,主要的目的是为了保证论文集的质量,不让论文格式出现五花八门的情况,确保会议后被 ...

  4. IT English Collection(9) of Objective-C

    1 前言 今天我们来解除一篇有关Objective-C的介绍文章,详情如下. 2 详述 2.1 原文 Objective-C defines a small but powerful set of e ...

  5. mysql 5.6 设置慢查询

    mysql 5.6 开启慢查询日志 slow_query_log = on #开启慢查询 1 或者 on long_query_time = 3 #记录超过的时间,单位是秒,默认是10s slow_q ...

  6. windows服务器性能监控工具、方法及关键指标

    原文:http://www.cnblogs.com/liulun/p/3543777.html 监控方法 推荐使用windows自带的“性能监视器”(老版本的windows叫性能计数器)来监控服务器的 ...

  7. 此项目的默认Web访问模式设置为文件共享, 但是无法从路径(此为转贴)

    故障现象: 当你打开ASP.NET Web项目时,如果出现这样的错误提示:提示窗口标题: Web访问失败提示内容: 此项目的默认Web访问模式设置为文件共享, 但是无法从路径“...”打开“...”处 ...

  8. NSString字符串类型-学习总结

    1.字符串的创建 (1)创建常量字符串 NSString *str = @"This is a String"; //str是变量名 (2)创建空的字符串,给字符串赋值 NSStr ...

  9. 7 RandomAccessFile读取文件内容保存--简单例子(需要验证)

    import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; /** * 读取动态产生的文件内容 */ publ ...

  10. hdu 5671 矩阵变换

    Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...