number of sinks time limit: 3000ms memory limit: 128000KB 64-bit integer: Java class Name: Previous question submit run result statistics Discussion Edition next topic description Nanyang Polytechnic Campus There are some rivers and some lakes, and now we think of them as pools, Suppose there is a map of a place in our school, and this map only identifies whether it is a pool, and now that your task is coming, please use a computer to figure out how many pools there are in the map. Enter the first line to enter an integer n, representing a total of n sets of test data each set of data is the number of rows of the map first entered m (0<m< -) and the number of columns N (0<n< -), then enter the number of n for each row of the next m row, indicating whether there is water or no water (1 means the pool is here, and 0 is the ground) output outputs the number of pools in the map. It is important to note that each pool side (up and down four positions) can be considered to be the same pool if it is a sink. Sample Input23 41 0 0 0 0 0 1 11 1 1 05 51 1 1 1 00 0 1 0 10 0 0 0 01 1 1 0 00 0 1 1 1Sample Output23
T is a very simple topic with a deep search code attached below
#include <stdio.h>inta[101][101],n,m,n,i,j;voidDfsintXinty) { if(x>=0&&x<=m&&y>=0&&y<=n&&a[x][y]==1) A[x][y]=0; Else return ; DFS (x+1, y); DFS (x-1, y); DFS (x, y+1); DFS (x, y-1);}intMain () {scanf ("%d",&N); while(n--) {scanf ("%d%d",&m,&N); for(i=0; i<m;i++) for(j=0; j<n;j++) scanf ("%d",&A[i][j]); intcount; for(count=i=0; i<m;i++) for(j=0; j<n;j++) { if(a[i][j]==1)//if there's a pool.{Count++; DFS (I,J); }} printf ("%d\n", Count); } return 0;}
Number of pools-----There are several blocks in the chart.