这是一道纯正的深度优先搜索题目。

题目要求在有多少个不同的块,而不同块的定义则是,一个块中的任意一点和l另一个块中的任意一点不会相连,而相连的定义则是

在横向、纵向和对角线上相连。

#include<stdio.h>
#include<string.h>
char map[101][101];
int m,n;
int search(int x,int y)
{
if(x<0||y<0||x>m||y>n)
return 0;
if(map[x][y]=='@')
{
map[x][y]='1';
search(x,y+1);
search(x+1,y+1);
search(x+1,y);
search(x+1,y-1);
search(x,y-1);
search(x-1,y-1);
search(x-1,y);
search(x-1,y+1);
return 1;
}
if(map[x][y]=='*')
{
map[x][y]='1';
return 0;
}
if(map[x][y]=='1')
return 0;
}
int main()
{

while(scanf("%d%d",&m,&n)!=EOF)
{
getchar();
if(m==0||n==0)
break;
memset(map,'\0',sizeof(map));
int i,j,ans=0,t;
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%c",&map[i][j]);
}
getchar();
}
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
if(map[i][j]=='*'||map[i][j]=='1')
continue;
t=search(i,j);
if(t!=0)
ans++;
}
printf("%d\n",ans);
}
return 0;
}

UVA 572的更多相关文章

  1. UVA 572 Oil Deposits油田(DFS求连通块)

    UVA 572     DFS(floodfill)  用DFS求连通块 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format: ...

  2. 2018 Spring Single Training B (uva 572,HihoCoder 1632,POJ 2387,POJ 2236,UVA 10054,HDU 2141)

    这场比赛可以说是灰常的水了,涨信心场?? 今下午义务劳动,去拿着锄头发了将近一小时呆,发现自己实在是干不了什么,就跑到实验室打比赛了~ 之前的比赛补题补了这么久连一场完整的都没补完,结果这场比完后一小 ...

  3. UVA 572 -- Oil Deposits(DFS求连通块+种子填充算法)

    UVA 572 -- Oil Deposits(DFS求连通块) 图也有DFS和BFS遍历,由于DFS更好写,所以一般用DFS寻找连通块. 下述代码用一个二重循环来找到当前格子的相邻8个格子,也可用常 ...

  4. UVA 572 油田连通块-并查集解决

    题意:8个方向如果能够连成一块就算是一个连通块,求一共有几个连通块. 分析:网上的题解一般都是dfs,但是今天发现并查集也可以解决,为了方便我自己理解大神的模板,便尝试解这道题目,没想到过了... # ...

  5. UVa 572 油田(DFS求连通块)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. UVA 572 (dfs)

    题意:找出一块地有多少油田.'@'表示油田.找到一块就全部标记. #include<cstdio> #define maxn 110 char s[maxn][maxn]; int n,m ...

  7. uva 572 oil deposits——yhx

    Oil Deposits  The GeoSurvComp geologic survey company is responsible for detecting underground oil d ...

  8. UVA - 572 Oil Deposits(dfs)

    题意:求连通块个数. 分析:dfs. #include<cstdio> #include<cstring> #include<cstdlib> #include&l ...

  9. 暴力求解——UVA 572(简单的dfs)

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

随机推荐

  1. 【树莓派】使用树莓派制作img镜像(二)

    树莓派制作的镜像,需要如何使用,这里直接引用目前树莓派官方的文章,不再重复描述: 参考:http://shumeipai.nxez.com/2013/08/31/usb-image-tool.html ...

  2. Codeforces Round #262 (Div. 2)

    A #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  3. winform小程序---猜拳小游戏

    因为学的时间不长,所以借鉴了一些资料做了这个小程序,大家共同学习,共同进步.感觉很有自信,世上无难事,只怕有心人. using System; using System.Collections.Gen ...

  4. JQuery_进阶选择器

    在简单选择器外,还有一些进阶的选择器方便我们更精准的选择元素. 1.群组选择器 可以将相同的样式合并 <script type="text/javascript" src=& ...

  5. 转!!mysql order by 中文排序

    1. 在MySQL中,我们经常会对一个字段进行排序查询,但进行中文排序和查找的时候,对汉字的排序和查找结果往往都是错误的. 这种情况在MySQL的很多版本中都存在. 如果这个问题不解决,那么MySQL ...

  6. Listview 隐藏item

    隐藏某一项item(防止list改变后导致复用convertview而错乱--如果删掉list中的该项,会导致复用convertview混乱) 方法: convertView.setVisibilit ...

  7. 无法获取有关Windows NT 组\用户‘组\用户’的信息,错误代码0x5(Microsoft SQL Server,错误:15404)

    配置了复制,在删除某个发布的时候,突然报此错误,无法删除此发布:   使用语句修改:  ALTER AUTHORIZATION ON DATABASE:: [数据库名] TO [sa] 即修改数据库的 ...

  8. centos apache源码安装过程记录

    1.下载相关源文件 wget http://mirror.bjtu.edu.cn/apache/httpd/httpd-2.4.18.tar.gzwget http://mirrors.hust.ed ...

  9. NGUI Camera's raycast hit through the UI Layer issue

    Raycast into GUI?http://forum.unity3d.com/threads/raycast-into-gui.263397/ << ; Ray myray = UI ...

  10. 关于JS一些验证邮箱的一些问题

    if (type == "Email") { var strText = $("#EmailSaveText").val(); //strReg = /^\w+ ...