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 pocket. 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 Input
Sample Output
0122
Sourcemid-central USA 1997
1#include <stdio.h>2#include <iostream>3 using namespacestd;4 intn,m;5 Charmap[ the][ the];6 intrx[]={0,0,1,-1,1,1,-1,-1};7 intry[]={1,-1,0,0,1,-1,1,-1};8 voidDelintIintj)9 {Tenmap[i][j]='*'; One intx,y,t; A for(t=0;t<8; t++) - { -x=i+Rx[t]; they=j+Ry[t]; - if(x>=0&&x<n&&y>=0&&y<m&&map[x][y]=='@') - del (x, y); - } + } - intMain () + { A while(SCANF ("%d%d", &n,&m)!=eof&&n&&m) at { - inti,j,num=0; - for(i=0; i<n;i++) - for(j=0; j<m;j++) -Cin>>Map[i][j]; - for(i=0; i<n;i++) in for(j=0; j<m;j++) - if(map[i][j]=='@') to { +num++; - del (I,J); the } *printf"%d\n", num); $ }Panax Notoginseng return 0; -}
HDU 1241Oil Deposits (DFS)