Codevs 1569 Best Green grass

Source: Internet
Author: User

1569 Best Green Grass

time limit: 1 sspace limit: 128000 KBtitle level: Golden GoldTitle Description Description


Bessie was planning the day to chew the green grass of the spring, gazing at the beloved of the farmer John and being divided
Cut to the grasslands of R (1 <= r <= 100) row and C (1 <= C <= 100) column. She wants to count the meadows.
How many bushes are there?

Each grass is represented on the map with a ' # ', or two ' # ' together (but not on a diagonal),
Give a map of the Meadows, and tell Betsy how many bushes there are in the meadow.

For example, below is a meadow map r=5, c=6:

.#....
.. #...
.. #.. #
...##.
.#....

There are 5 grass in this meadow. (;(2,3) + (3+3);(3,6);(bis) + (4,5);(5,2)

Enter a description Input Description


* Line 1th: 2 integers separated by a space R, C

* 2nd to R+1: Pasture map Information

Output description Output Description

* The total number of grass on the pasture.

Sample input Sample Input

5 6
.#....
.. #...
.. #.. #
...##.
.#....

Sample output Sample Output

5

1#include <iostream>2#include <cstring>3#include <cstdio>4 #defineN 1055 using namespacestd;6 intn,m,a[n][n],ans,dx[]={0,0,1,-1},dy[]={1,-1,0,0};7 voidDfsintXinty) {8a[x][y]=0;9      for(intI=0;i<4; i++){Ten         intxx=x+dx[i],yy=y+Dy[i]; One         if(a[xx][yy]==1) DFS (XX,YY); A     } - } - intMain () the { -     CharC; -Memset (A,0,sizeof(a)); -scanf"%d%d",&n,&m); +      for(intI=1; i<=n;i++){ -          for(intj=1; j<=m;j++){ +Cin>>C; A             if(c=='#') a[i][j]=1; at             if(c=='.') a[i][j]=0; -         } -     } -      for(intI=1; i<=n;i++){ -          for(intj=1; j<=m;j++){ -             if(a[i][j]==1) Dfs (I,J), ans++; in         } -     } toprintf"%d", ans); +     return 0; -}

Codevs 1569 Best Green grass

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.