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