Oil deposits
| Time Limit: 3000MS |
|
Memory Limit: Unknown |
|
64bit IO Format: %lld &%llu |
Submit Status
Description
The 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 grid begins with a line containing
mand
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 and. Following this is
mLines of
NCharacters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either '*', representing the absence of oil, or '@', representing an 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
1 1*3 5*@*@***@***@*@*1 8@@****@*5 5****@*@@*@*@**@@@@*@@@**@0 0
Sample Output
0122
It's a very simple topic! Understand the eight direction how to express, and how to give different classes of block numbering.
#include <iostream> #include <string.h>using namespace Std;char cnt[101][101];int vis[101][101];int count, m,n;void dfs (int x,int y, int id) {for (Int. i=-1; i<=1; i++) for (int j=-1; j<=1; J + +) { int tx=x+i; int ty=y+j; if (tx>=0&&ty>=0&&tx<m&&ty<n&&cnt[tx][ty]== ' @ ' &&!vis[tx][ty ]) {vis[x][y]=id; DFS (TX,TY,ID); }} return; int main () {while (cin>>m>>n,m) {memset (vis,0,sizeof (VIS)); for (int i=0, i<m; i++) for (int j=0; j<n; j + +) cin>>cnt[i][j]; int count=0; for (int k=0, k<m; k++) for (int q=0; q<n; q++) {if (!vis[k][q]&&cnt[k][q ]== ' @ ') {vis[k][q]=++count; DFS (K,q,count); }} cout<<count<<endl; } return 0;}
Uva 572 Oil Deposits