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

题目要求在有多少个不同的块,而不同块的定义则是,一个块中的任意一点和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. WinForm关闭窗体彻底的退出方式

    //System.Environment.Exit(0); //Process.GetCurrentProcess().Kill(); //System.Threading.Thread.Curren ...

  2. 系统收到了多个不同的 Content-Disposition 标头。为了避免遭到 HTTP 响应拆分攻击,这种情况是不允许的。

    今天使用Struts2进行上传下载的时候发现了一个现象 我的Struts2配置文件 <action name="share_ExportExcel" class=" ...

  3. centos7 安装mysql5.7.16

    1 下载地址http://dev.mysql.com/downloads/mysql/#downloads 2. 解压 -linux-glibc2.-x86_64.tar.gz 3.移动解压出来的文件 ...

  4. Web1.0、Web2.0、Web3.0的主要区别

    Web1.0:以静态.单向阅读为主,网站内信息可以直接和其他网站信息进行交互,能通过第三方信息平台同时对多家网站信息进行整合使用. Web2.0:以分享为特征的实时网络,用户在互联网上拥有自己的数据, ...

  5. 在centos6.5中安装scp和lrzsz

    简介   scp用于在两台centos中传输文件用的,lrzsz用于在xshell上传输本地文件到远程centos服务器上用的  1.安装scp [root@localhost ~]# scp -ba ...

  6. E:Sudoku

    总时间限制: 2000ms 内存限制: 65536kB描述Sudoku is a very simple task. A square table with 9 rows and 9 columns ...

  7. IIS7配置asp网站

    An error occurred on the server when processing the URL. Please contact the system administrator. If ...

  8. iOS开发UI篇—Quartz2D简单使用(二)

    iOS开发UI篇—Quartz2D简单使用(二) 一.画文字 代码: // // YYtextview.m // 04-写文字 // // Created by 孔医己 on 14-6-10. // ...

  9. ubuntu+php5.6+redis+mysql5.5+nginx

    thinkphp : location / {                if (!-e $request_filename) {                        rewrite ^ ...

  10. Positive-definite matrix

    In linear algebra, a symmetric n × n real matrix M is said to be positive definite if zTMz is positi ...