当前位置: 首页 > 专家说 > 石油 > 正文

acm 勘探油田

关注热度:84
相关推荐 你可能关注 点击排行 我要评论

【专家解说】:简单的搜索题,可以用DFS解决。以下是我的代码,LZ可以看一下: #include<iostream> #include<cstring>using namespace std;const int N=105;char s[N][N]; bool map[N][N]; int d[8][2]={1,0,0,1,-1,0,0,-1,1,1,1,-1,-1,1,-1,-1}; int n,m;void dfs(int x,int y) { int i,tx,ty; map[x][y]=false; i=0; while(i<8) { tx=x+d[i][0]; ty=y+d[i][1]; if(tx>=0&&ty>=0&&tx<n&&ty<m&&s[tx][ty]=='@'&&map[tx][ty]) dfs(tx,ty); i++; } return; }int main() { int i,j,ans; while(scanf("%d%d",&n,&m)==2) { i=0; while(i<n) scanf("%s",s[i++]); memset(map,true,sizeof(map)); ans=0; i=0; while(i<n) { j=0; while(j<m) { if(s[i][j]=='@'&&map[i][j]) { dfs(i,j); ans++; } j++; } i++; } printf("%d\n",ans); } return 0; }
 
关键词: 油田

[ 专家说搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]
 
相关专家说推荐
 
0条 [查看全部]  相关评论
 
相关资讯
热门推荐
 
 
网站首页 | 联系我们 | 排名推广 | 广告服务 | 积分换礼 | 网站留言