3385: [Usaco2004 nov]lake counting number Pond

Source: Internet
Author: User

3385: [Usaco2004 nov]lake counting number pond time limit:1 Sec Memory limit:128 MB
Submit:22 solved:21
[Submit] [Status] [Discuss] Description farmer John's farm can be represented as a rectangle of NXM (1≤n,m≤100) squares. As a result of recent rains, ponds were formed in different places on John's farm. Each square has water (' W ') or no stagnant water ('. ’). The farmer John is going to count the number of ponds that have formed on his farm.    A pond is a series of connected and stagnant squares, each of which is considered to be connected to the eight squares around each square. A pattern of John's farm is now given, which calls for the number of ponds on the farm to be exported.    Input line 1th: two integers n and m separated by a space. 2nd to N+1: A row of M characters per line represents the state of a row of squares on John's farm. Each character is either ' W ' or '. ', there are no spaces between the characters. The number of ponds on the Output John Farm.

Sample Input10 12
W........ Ww.
. Www..... Www
.... Ww... Ww.
......... Ww.
......... W..
.. W...... W..
. W.w ..... Ww.
W.w.w ..... W.
. W.W ... W.
.. W....... W.Sample Output3HINT

There are 3 ponds: one in the upper left corner, one in the lower left corner and one along the right border

Source

Gold

The puzzle: In the beginning actually WA a bit, and found that the subroutine forgot to apply the local variable i a TT

Other really did not, direct irrigation seconds, do not understand why this can also become a gold group ... But looks like NOV2004 only the gold group = =

1/**************************************************************2Problem:33853 User:hansbug4 language:pascal5 result:accepted6Time:8Ms7Memory:344KB8****************************************************************/9  Ten ConstDirArray[1..8,1..2] ofLongint= ((0,1),(0,-1),(1,0),(-1,0),(1,-1),(-1,1),(1,1),(-1,-1)); One var A I,j,k,l,m,n,ans:longint; - Ch:char; -A:Array[0..101,0..101] ofLongint; the procedureFloodFill (x,y:longint); -           varI:longint; -           begin -                ifa[x,y]=0  Thenexit; +a[x,y]:=0; -                 fori:=1  to 8  Do +                    ifA[x+dir[i,1],y+dir[i,2]]=1  ThenFloodFill (X+dir[i,1],y+dir[i,2]); A           End; at begin - readln (n,m); -Fillchar (A,sizeof (a),0); -       fori:=1  toN Do -           forj:=1  toM Do -              begin in read (CH); -                   ifUpCase (ch) ='W'  Thena[i,j]:=1; to                   ifJ=m ThenReadln; +              End; -ans:=0; the       fori:=1  toN Do *           forj:=1  toM Do $              ifa[i,j]=1  ThenPanax Notoginseng                 begin - Inc (ANS); the FloodFill (i,j); +                 End; A writeln (ans); the Readln; + End.

3385: [Usaco2004 nov]lake counting number Pond

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.