Hangzhou Electric 1241--oil Deposits (DFS)

Source: Internet
Author: User

Oil deposits

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 17887 Accepted Submission (s): 10298


Problem DescriptionThe Geosurvcomp Geologic Survey company are responsible for detecting underground oil deposits. Geosurvcomp works with one large rectangular region of land at a time, and creates a grid that divides the land into Numer OUs square plots. It then analyzes each plot separately, using a sensing equipment to determine whether or not of the plot contains oil. A plot containing oil is called a pocket. If the pockets is adjacent, then they is part of the same oil deposit. Oil deposits can is quite large and may contain numerous pockets. Your job is to determine how many different oil deposits be contained in a grid.

Inputthe input file contains one or more grids. Each of the grids begins with a line containing M and N, the number of rows and columns in the grid, separated by a single space. If m = 0 It signals the end of the input; Otherwise 1 <= m <= and 1 <= n <= 100. Following this is m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and are either ' * ', representing the absence of oil, or ' @ ', representing a oil PO Cket.

Outputfor each grid, output the number of distinct oil deposits. The different pockets is part of the same oil deposit if they is adjacent horizontally, vertically, or diagonally. An oil deposit won't contain more than pockets.

Sample INPUT1 1 * 3 5 *@*@* **@** *@*@* 1 8 @@****@* 5 5 ****@ *@@*@ *@**@ @@@*@ @@**@ 0 0

Sample Output0 1 22

Sourcemid-central USA 1997

Recommendeddy | We have carefully selected several similar problems for you:1016 1010 1312 1242 1240//Mark →→
1#include <cstring>2#include <iostream>3 using namespacestd;4 #defineN 110;5 intm, N, I, J;6 7 intac[8][2]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}};8 intvis[ the][ the];9 Charmap[ the][ the];Ten intsum =0; One  A voidDFS (intXinty) - { -     intNX, NY; theVis[x][y] =1; -      for(intI=0; i<8; i++) -     { -NX = x + ac[i][0]; +NY = y + ac[i][1]; -         if(map[nx][ny]=='@'&&nx>=0&&nx<m&&ny>=0&&ny<n&&vis[nx][ny]==0) +         { A DFS (NX, NY); at         }  -     } - } -  -  - intMain () in { -      while(~SCANF ("%d%d", &m, &N), m) to     { +          for(i=0; i<m; i++) -              for(j=0; j<n; J + +) theCIN >>Map[i][j]; *memset (Vis,0,sizeof(Vis)); $sum =0;Panax Notoginseng          for(i=0; i<m; i++) -         { the              for(j=0; j<n; J + +) +             if(Map[i][j] = ='@'&&!Vis[i][j]) A             { the DFS (i, j); +sum++; -             } $         } $cout << sum <<Endl; -      -     } the     return 0; -}

Hangzhou Electric 1241--oil Deposits (DFS)

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.