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 ...
随机推荐
- CPU的大小端模式
不同体系结构的CPU,数据在内存中存放的排列顺序是不一样的. 存储器中对数据的存储是以字节(Byte)为基本单位的,因此,字(Word)和半字(Half-Word)在存储器中就有两种次序,分别称为:大 ...
- 【转】 Easy RadControl 之 RadGridView(Silverlight)
1.不显示第1列即列指示器(Row Indicators) 在 telerik:RadGridView中设置属性 RowIndicatorVisibility="Collapsed&qu ...
- 使用JavaScript实现复选框全选与取消的功能
实现效果: html代码: <body> <input type="checkbox" id="checkAll"/>全选<br& ...
- 使用CSS3动画模拟实现小球自由落体效果
使用纯CSS代码模拟实现小球自由落体效果: html代码如下: <div id="ballDiv"> <div id="ball">&l ...
- 在VBA中新建工作簿
用程序计算数据,得到不同公司.不同项目的数据结果,最终还要将每个公司的数据结果放在各自的单独文件中.这就需要在vba中新建.保存excel文件.掌握几个东西就能很熟练了:1.要想保存在当前目录下,需要 ...
- Spark的Straggler深入学习(2):思考Block和Partition的划分问题——以论文为参考
一.partition的划分问题 如何划分partition对block数据的收集有很大影响.如果需要根据block来加速task的执行,partition应该满足什么条件? 参考思路1:range ...
- [蟒蛇菜谱] Python封装shell命令
# -*- coding: utf-8 -*- import os import subprocess import signal import pwd import sys class MockLo ...
- 把crosswalk打包到cordova项目中
(1)从Crosswalk官网下载Cordova Android (ARM) 点击下载 (2)解压压缩包到任意目录 (3)创建工程 cordova工程 cordova create Crosswalk ...
- portotype
[ portotype ] [语法] function :function Name是创建新的函数的名称 body : body可以选项,包含调用该函数时被执行的JScrtipt 代码的字符串. ...
- 关于反射率(reflectance)
首先,BRDF的内容因为见的多,用的多,所以比较容易理解.但是由BRDF引申出来的反射率,跟BRDF比不太常见,有些东西反而不易理解.尤其是组里的某大牛都不甚清楚(说明这个问题不太容易或者太过冷门), ...