1751: [Usaco2005 qua]Lake Counting

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 190  Solved: 150
[Submit][Status][Discuss]

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.

HINT

 

Source

Gold

题解:直接萌萌哒DFS秒之,经典的普及组难度基础题,水水哒

(Tip:38行的dfs(a1,a2)貌似只有这样写在本机才能对,提交也能A;很神奇的是如果直接写dfs(i,j)的话在本机就会出现带入的是(1,1)结果进去的是(2,2)QAQ,然后各种神奇跪OTL,更神奇的是这个在本机都跪成狗的程序居然submit之后也能A(QAQ),求神犇解释)

 var
i,j,k,l,m,n,a1,a2:longint;
c1:char;
a:array[..,..] of longint;
procedure dfs(x,y:longint);inline;
begin
a[x,y]:=;
if a[x-,y-]= then dfs(x-,y-);
if a[x,y-]= then dfs(x,y-);
if a[x+,y-]= then dfs(x+,y-);
if a[x-,y+]= then dfs(x-,y+);
if a[x,y+]= then dfs(x,y+);
if a[x+,y+]= then dfs(x+,y+);
if a[x-,y]= then dfs(x-,y);
if a[x+,y]= then dfs(x+,y);
end;
begin
readln(n,m);
fillchar(a,sizeof(a),);
for i:= to n do
begin
for j:= to m do
begin
read(c1);
case c1 of
'W':a[i,j]:=;
'.':a[i,j]:=;
end;
end;
readln;
end;
l:=;
for i:= to n do
for j:= to m do
if a[i,j]= then
begin
a1:=i;a2:=j;
inc(l);dfs(a1,a2);
end;
writeln(l);
readln;
end.

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

  1. bzoj1751 [Usaco2005 qua]Lake Counting

    1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 168  Solved: 130 [ ...

  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. JSON数据格式中的引号

    JSON数据中必须使用双引号: $.getJSON,的输入必须是正确的JSON数据,否则不会执行回调函数: $.parseJSON的输入必须是正确的JSON数据,否则会有异常:

  2. 不使用模板导出Excel(C#版本)

    不多说,直接上干货! using System; using System.Collections.Generic; using System.Linq; using System.Web; usin ...

  3. 支持Angular 2的表格控件

    前端框架一直这最近几年特别火的一个话题,尤其是Angular 2拥有众多的粉丝.在2016年9月份Angular 2正式发布之后,大量的粉丝的开始投入到了Angular 2的怀抱.当然这其中也包括我. ...

  4. java算法 蓝桥杯 高精度加法

    问题描述 在C/C++语言中,整型所能表示的范围一般为-231到231(大约21亿),即使long long型,一般也只能表示到-263到263.要想计算更加规模的数,就要用软件来扩展了,比如用数组或 ...

  5. angular表格分页

    <!doctype html> <html lang="en" > <head> <meta charset="UTF-8&qu ...

  6. 如何给 UILable 添加横线

    类似淘宝上的原价现价,原价上一般都会有一条横线,这种效果怎么实现呢?其实相当的简单,我们只需要重写自定义的lable的 - (void)drawRect:(CGRect)rect 方法就行了. 具体实 ...

  7. 【原创】梵高油画用深度卷积神经网络迭代十万次是什么效果? A neural style of convolutional neural networks

    作为一个脱离了低级趣味的码农,春节假期闲来无事,决定做一些有意思的事情打发时间,碰巧看到这篇论文: A neural style of convolutional neural networks,译作 ...

  8. MYSQL:基础—存储过程

    MYSQL:基础-存储过程 快速入门 理解: 迄今为止,我们学过的大多数SQL语句都是针对一个或多个表的单条语句.但是并不是所有的操作都是可以用一条语句来完成的,经常有一些操作是需要多条语句配合才能完 ...

  9. svn conflicts: local delete, incoming delete upon update

    svn  st查看更新的时候发现存在conflicts,提示很多 local delete, incoming delete upon update , $:svn st ? C IMIRROR.T3 ...

  10. .Net程序员学用Oracle系列(16):访问数据库(ODP.NET)

    1..Net for Oracle 常见数据库驱动 1.1.微软提供的驱动 1.2.甲骨文提供的驱动 1.3.其它厂商提供的驱动 2.ODP.NET 常见问题分析 2.1.参数化问题 2.2.方法调用 ...