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. 浅谈JVM内存区域划分

    好吧,虽说真的有看过<深入分析Java Web技术内幕>一书,但当时看的时候还是一知半解,稀里糊涂的看完了.本来是打算暑假拿起来再看一遍的,但是早两天一个阿里学长给我做了个小面试,让我颇受 ...

  2. Bring it on

    I am going to open a whole new English Blog here. Most blogs here would be computer technologies, in ...

  3. c指针点滴1

    #include <stdio.h> #include <stdlib.h> void main() { ; int *p = &num;//&num是一个地址 ...

  4. hdu 4586 Play the Dice(概率dp)

    Problem Description There is a dice with n sides, which are numbered from 1,2,...,n and have the equ ...

  5. mysql插入数据时,中文乱码

    MySQL 插入数据时,中文乱码问题的解决(转) 当向 MySQL 数据库插入一条带有中文的数据形如 insert into employee values(null,'张三','female','1 ...

  6. php之手机号码查归属地

    免费手机号码归属地API查询接口 一.淘宝网API API地址: http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=1585078144 ...

  7. AJAX上传文件

    function up_files() { var fileSelect = document.getElementById('file-select'); var files = fileSelec ...

  8. http接口测试浏览器插件

    http接口测试浏览器插件: Chrome: https://chrome.google.com/webstore/detail/chrome-poster/cdjfedloinmbppobahmon ...

  9. 泛型 Field 和 SetField 方法 (LINQ to DataSet)

    LINQ to DataSet 为 DataRow 类提供用于访问列值的扩展方法:Field 方法和 SetField 方法.这些方法使开发人员能够更轻松地访问列值,特别是 null 值.DataSe ...

  10. Direct3D 11的资源

    资源(Resource) 如果把渲染流水线比喻成汽车装配线,资源就是流水线上需要输入的东西. 资源可分为两类:Textures(纹理)和Buffers(缓冲区). Textures可以简单地分为1维, ...