3385: [Usaco2004 Nov]Lake Counting 数池塘

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 22  Solved: 21
[Submit][Status][Discuss]

Description

    农夫约翰的农场可以表示成N×M(1≤N,M≤100)个方格组成的矩形.由于近日的降雨,
在约翰农场上的不同地方形成了池塘.每一个方格或者有积水(’W’)或者没有积水(’.’).农夫约翰打算数出他的农场上共形成了多少池塘.一个池塘是一系列相连的有积水的方格,每一个方格周围的八个方格都被认为是与这个方格相连的.
    现给出约翰农场的图样,要求输出农场上的池塘数.

Input

    第1行:由空格隔开的两个整数N和M.
    第2到N+1行:每行M个字符代表约翰农场的一排方格的状态.每个字符或者是’W’或者
是’.’,字符之间没有空格.

Output

    约翰农场上的池塘数.

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

HINT

共有3个池塘:一个在左上角,一个在左下角,还有一个沿着右边界

Source

Gold

题解:一开始居然WA了一下,结果发现子程序里面忘申请局部变量i了TT

别的实在没了,直接灌水秒之,不明白这个为啥也能成为金组。。。不过貌似NOV2004只有金组的= =

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ const dir:array[..,..] of longint=((,),(,-),(,),(-,),(,-),(-,),(,),(-,-));
var
i,j,k,l,m,n,ans:longint;
ch:char;
a:array[..,..] of longint;
procedure floodfill(x,y:longint);
var i:longint;
begin
if a[x,y]= then exit;
a[x,y]:=;
for i:= to do
if a[x+dir[i,],y+dir[i,]]= then floodfill(x+dir[i,],y+dir[i,]);
end;
begin
readln(n,m);
fillchar(a,sizeof(a),);
for i:= to n do
for j:= to m do
begin
read(ch);
if upcase(ch)='W' then a[i,j]:=;
if j=m then readln;
end;
ans:=;
for i:= to n do
for j:= to m do
if a[i,j]= then
begin
inc(ans);
floodfill(i,j);
end;
writeln(ans);
readln;
end.

3385: [Usaco2004 Nov]Lake Counting 数池塘的更多相关文章

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

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

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

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

  3. 1630/2023: [Usaco2005 Nov]Ant Counting 数蚂蚁

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

  4. bzoj2023[Usaco2005 Nov]Ant Counting 数蚂蚁*&&bzoj1630[Usaco2007 Demo]Ant Counting*

    bzoj2023[Usaco2005 Nov]Ant Counting 数蚂蚁&&bzoj1630[Usaco2007 Demo]Ant Counting 题意: t个族群,每个族群有 ...

  5. bzoj1630 / bzoj2023 [Usaco2005 Nov]Ant Counting 数蚂蚁

    Description     有一天,贝茜无聊地坐在蚂蚁洞前看蚂蚁们进进出出地搬运食物.很快贝茜发现有些蚂蚁长得几乎一模一样,于是她认为那些蚂蚁是兄弟,也就是说它们是同一个家族里的成员.她也发现整个 ...

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

    题意 题目描述的很清楚...  有一天,贝茜无聊地坐在蚂蚁洞前看蚂蚁们进进出出地搬运食物.很快贝茜发现有些蚂蚁长得几乎一模一样,于是她认为那些蚂蚁是兄弟,也就是说它们是同一个家族里的成员.她也发现整个 ...

  7. BZOJ 2023 [Usaco2005 Nov]Ant Counting 数蚂蚁:dp【前缀和优化】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2023 题意: 有n个家族,共m只蚂蚁(n <= 1000, m <= 1000 ...

  8. 【bzoj2023/1630】[Usaco2005 Nov]Ant Counting 数蚂蚁 dp

    题解: 水题 f[i][j] 前i种用了j个,前缀和优化就可以了

  9. bzoj 2023: [Usaco2005 Nov]Ant Counting 数蚂蚁【生成函数||dp】

    用生成函数套路推一推,推完老想NTT--实际上把这个多项式乘法看成dp然后前缀和优化一下即可 #include<iostream> #include<cstdio> using ...

随机推荐

  1. List与Linkedlist、Arrylist、Vector、Map应用

    1.List与LinkedList      List是数组链表     LinkedList是指针链表     选择List还是LinkedList要看你的使用特点.       数组链表访问快,复 ...

  2. 在DataTable数据类型最后增加一列,列名为“Column”,内容都为“AAA”

    DataTable dt = new DataTable(); dt.Columns.Add("Column", typeof(string)); foreach (DataRow ...

  3. C# winform初学者实例

    快递单打印通 下载地址: http://pan.baidu.com/s/1nue5ifn

  4. 6.00.1x Introduction to computation

    6.00 Introduction to Computer Science                  and  Programming • Goal: –Become skillful at ...

  5. pytho查找斐波那契序列中的值

    ''' 实现斐波那契序列,查找其中第N个数的值 ''' def FeiBSequence(list,N): length=len(list); i=0; while i<length: if N ...

  6. 华为oj---合并数组

    题目标题: 将两个整型数组按照升序合并,并且过滤掉重复数组元素 详细描述: 接口说明 原型: voidCombineBySort(int* pArray1,intiArray1Num,int* pAr ...

  7. [CSS3] 学习笔记-CSS3选择器详解(一)

    1.属性选择器 在CSS3中,追加了3个属性选择器,分别为:[att*=val].[att^=val]和[att$=val],使得属性选择器有了通配符的概念. <!doctype html> ...

  8. loadrunner解决浏览器死机问题

    初次接触loadrunner时,遇到很多问题.浏览器崩溃以及录不到脚本就折磨了一周时间.最后终于解决 一.浏览器崩溃问题 1.退出安全卫士和防火墙 2.去掉IE第三方扩展.工具-Internet选项- ...

  9. 时间处理之strtotime

    strtotime (PHP 4, PHP 5, PHP 7)strtotime - 将任何英文文本的日期时间描述解析为 Unix 时间戳说明 int strtotime ( string $time ...

  10. [UWP]依赖属性2:使用依赖属性

    5. 完整的自定义依赖属性 5.1 定义 /// <summary> /// 标识 Title 依赖属性. /// </summary> public static reado ...