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 ...
随机推荐
- jvm 之结构与机制
本文旨在给所有希望了解JVM(Java Virtual Machine)的同学一个概念性的入门,主要介绍了JVM的组成部分以及它们内部工作的机制和原理.当然本文只是一个简单的入门,不会涉及过多繁杂的参 ...
- yum只下载不安装:yumdownloader
如果只想通过yum下载软件的安装包,但是不需要进行安装的话,可以使用 yumdownloader 命令. yumdownloader 命令在软件包 yum-utils 里面. 先安装 yum-util ...
- MySQL数据库4 - 查看数据表
一. 查看表的基本结构 语法:DESCRIBE/DESC TABLE_NAME 查询结果含义: Field: 字段名 Type: 字段类型 Null: 是否可以为空 Key: 是否编制索引 defau ...
- Java 验证码工具类
package com.wuyu.util; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import ...
- How can I protect derived classes from breaking when I change the internal parts of the base class?
How can I protect derived classes from breaking when I change the internal parts of the base class? ...
- NPOI 单元格(cell) 格式参数
NPOI 单元格(cell) 将格式设为文本 在网上找了很久,都没有关于如何设置的信息,没办法查了下NPOI的源码终于找到了方法.这里共享下,就是“@”参数 ICellStyle cellStyle ...
- 【转】Sqlite 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该...
开发环境: vs2010+.net framework 4.0+ System.Data.SQLite.DLL (2.0)今天在做Sqlite数据库测试,一运行程序在一处方法调用时报出了一个异常 混合 ...
- HSLA颜色
CSS2中色彩模式只有RGB色彩模式(RGB即RED.Green.BLue)和十六进制模式,为了能支持 透明opacity 的Alpha值,CSS3又增加了RGBA色彩模式(RGBA即RED.Gree ...
- 操作系统学习笔记(五)--CPU调度
由于第四章线程的介绍没有上传视频,故之后看书来补. 最近开始学习操作系统原理这门课程,特将学习笔记整理成技术博客的形式发表,希望能给大家的操作系统学习带来帮助.同时盼望大家能对文章评论,大家一起多多交 ...
- overflow属性
css属性overflow属性定义溢出元素内容区的内容会如何处理.如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制. 参数是scroll时候,必会出现滚动条. 参数是auto时候,子 ...