Number of pools-----There are several blocks in the chart.

Source: Internet
Author: User

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.

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.