标签:
Problem Description
The GeoSurvComp geologic survey company is 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 numerous square plots. It then analyzes each plot separately, using sensing
equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket.
If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large
and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid
#include<cstdio> int dir[8][2]={{0,-1},{0,1},{-1,0},{1,0},{-1,-1},{1,-1},{-1,1},{1,1}}; char map[100][100]; int count; int m,n; void dfs(int x,int y) { int i=0; if(x<0||y<0||x==m||y==n) return; if(map[x][y]==‘*‘) return; else { map[x][y]=‘*‘; for(i=0;i<8;i++) dfs(x+dir[i][0],y+dir[i][1]); } } int main() { int i=0; int j=0; while(~scanf("%d%d",&m,&n)&&m) { for(i=0;i<m;i++) scanf("%s",map[i]); count=0; for(i=0;i<m;i++) for(j=0;j<n;j++) { if(map[i][j]==‘@‘) { count++; dfs(i,j); } } printf("%d\n",count); } return 0; }
标签:
原文地址:http://www.cnblogs.com/test404/p/5453070.html