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.admin管理员组文章数量:1648642
1 1 * 3 5 *@*@* **@** *@*@* 1 8 @@****@* 5 5 ****@ *@@*@ *@**@ @@@*@ @@**@ 0 0
0 1 2 2
题目大意:联通块问题,很简单,不过我就想敲下这种简单的dfs
ac代码
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
int mp[105][105],vis[105][105],n,m,ans;
int go[][2]={0,1,0,-1,1,-1,1,1,1,0,-1,0,-1,1,-1,-1};
void dfs(int x,int y)
{
if(x<0||x>=n||y<0||y>=m||vis[x][y]||mp[x][y]=='*')
return;
vis[x][y]=1;
for(int i=0;i<8;i++)
{
int xx=x+go[i][0];
int yy=y+go[i][1];
dfs(xx,yy);
}
}
int main()
{
while(scanf("%d%d",&n,&m)==2&&n&&m)
{
memset(vis,0,sizeof(vis));
ans=0;
getchar();
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
scanf("%c",&mp[i][j]);
getchar();
}
for(int i=0;i<n;i++)\
{
for(int j=0;j<m;j++)
{
if(!vis[i][j]&&mp[i][j]=='@')
{
ans++;
dfs(i,j);
}
}
}
printf("%d\n",ans);
}
return 0;
}
版权声明:本文标题:Oil Deposits HDU - 1241 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729493500a1202675.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论