UVA 572 (dfs)
题意:找出一块地有多少油田。‘@’表示油田。找到一块就全部标记。
#include<cstdio> #define maxn 110 char s[maxn][maxn];
int n,m;
int ans;
int dir[][] = {{-,-},{-,},{-,},{,},{,},{,},{,-},{,-}}; void dfs(int x,int y)
{
s[x][y] = '*';
for(int i = ;i < ; i++){
int xx = x + dir[i][];
int yy = y + dir[i][];
if(xx >= && xx < m && yy >= && yy < n && s[xx][yy] == '@'){
dfs(xx,yy);
}
}
} int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%d%d",&m,&n) != EOF){
ans = ;
if(m == && n == )
break;
for(int i = ;i < m; i++)
scanf("%s",s[i]);
for(int i = ;i < m; i++){
for(int j = ;j < n; j++){
if(s[i][j] == '@'){
dfs(i,j);
ans++;
}
}
}
printf("%d\n",ans);
}
return ;
}
UVA 572 (dfs)的更多相关文章
- UVA 572 dfs求连通块
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...
- 【紫书】Oil Deposits UVA - 572 dfs求联通块
题意:给你一个地图,求联通块的数量. 题解: for(所有还未标记的‘@’点) 边dfs边在vis数组标记id,直到不能继续dfs. 输出id及可: ac代码: #define _CRT_SECURE ...
- UVA 572 Oil Deposits油田(DFS求连通块)
UVA 572 DFS(floodfill) 用DFS求连通块 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format: ...
- UVA 572 -- Oil Deposits(DFS求连通块+种子填充算法)
UVA 572 -- Oil Deposits(DFS求连通块) 图也有DFS和BFS遍历,由于DFS更好写,所以一般用DFS寻找连通块. 下述代码用一个二重循环来找到当前格子的相邻8个格子,也可用常 ...
- 2018 Spring Single Training B (uva 572,HihoCoder 1632,POJ 2387,POJ 2236,UVA 10054,HDU 2141)
这场比赛可以说是灰常的水了,涨信心场?? 今下午义务劳动,去拿着锄头发了将近一小时呆,发现自己实在是干不了什么,就跑到实验室打比赛了~ 之前的比赛补题补了这么久连一场完整的都没补完,结果这场比完后一小 ...
- UVa 572 油田(DFS求连通块)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA - 572 Oil Deposits(dfs)
题意:求连通块个数. 分析:dfs. #include<cstdio> #include<cstring> #include<cstdlib> #include&l ...
- 暴力求解——UVA 572(简单的dfs)
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- UVa 572 Oil Deposits(DFS)
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil ...
随机推荐
- android 保存Bitmap 到本地 哦
public String saveImage(Bitmap bmp) { File appDir = new File(Environment.getExternalStorageDirectory ...
- JS数组中every(),filter(),forEach(),map(),some()方法学习笔记!
ES5中定义了五种数组的迭代方法:every(),filter(),forEach(),map(),some(). 每个方法都接受两个参数:要在每一项运行的函数(必选)和运行该函数的作用域的对象-影响 ...
- AngularJs的UI组件ui-Bootstrap分享(九)——Alert
alert指令会在页面上显示一条提示消息,效果是这样: 代码为: <!DOCTYPE html> <html ng-app="ui.bootstrap.demo" ...
- java 文件压缩和解压(ZipInputStream, ZipOutputStream)
最近在看java se 的IO 部分 , 看到 java 的文件的压缩和解压比较有意思,主要用到了两个IO流-ZipInputStream, ZipOutputStream,不仅可以对文件进行压缩,还 ...
- 关于ssh调用远程后台命令挂住的解释
目前看到的最详细最全面的解释: http://www.snailbook.com/faq/background-jobs.auto.html
- 面向对象to1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 回头再看N层架构(图解)
不知不觉来博客园已经快两半了,时间过的真快. 这次的目标是再回顾一下传统的N层架构并且分析一下在DDD中的N层架构. 一.先来看一看传统的N层架构 N-层架构的出现,主要是由于观注点的分离而产生,这三 ...
- Parameter index out of range (2 > number of parameters, which is 1)
今天在实现一个功能时遇到一个问题,解决了很久.结果是#{}与${}使用错误的原因.但是具体原因还不是很清楚,写此篇总结,知道的可以交流. 具体描述为:通过教师的头衔(1高级讲师2首席讲师)及名称进行模 ...
- IT之梦
生活原本不孤单,可惜人们总爱感叹 日子其实很简单,而我却不甘平淡 工作中我尽情的挥洒热汗,只为让成功离自己更近一点 生活中我为人和善,只为人生的路上多一个伙伴 时间不等人,IT尚遥远 我愿舍身敬业,誓 ...
- python 字符串内建函数
方法 描述 string.capitalize() 把字符串的第一个字符大写 string.center(width) 返回一个原字符串居中,并使用空格填充至长度 width 的新字符串 string ...