A
来源:互联网 发布:芯片设计工程师 知乎 编辑:程序博客网 时间:2024/06/05 20:26
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.
1 1*3 5*@*@***@***@*@*1 8@@****@*5 5 ****@*@@*@*@**@@@@*@@@**@0 0
0122
题意:相邻的融合为一个,总共多少个油田
#include<stdio.h>#include<string.h>#define N 111char str[N][N];int a,b;int dir[8][2]={{1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,-1},{-1,1},{1,-1}};void fbs(int x,int y){ int i,n,m; for(i=0;i<8;i++) { n=x+dir[i][0]; m=y+dir[i][1]; if(n<0||m<0||n>a-1||m>b-1||str[n][m]=='*')continue; else str[n][m]='*'; fbs(n,m); }}int main(){ int i,j,count; while(scanf("%d%d",&a,&b)&&a!=0&&b!=0) { count=0; for(i=0;i<a;i++) scanf("%s",&str[i]); for(i=0;i<a;i++) { for(j=0;j<b;j++) { if(str[i][j]=='@') { str[i][j]='*'; fbs(i,j); count++; } } } printf("%d\n",count); } return 0;}
阅读全文
0 0