POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)
题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket 。
思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接变为*,这样可以避免重复搜索。
//POJ 1562 ZOJ 1709 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <stack>
#include <algorithm> using namespace std ; char ch[][] ;
int dir[][] = {{-,-},{-,},{-,},{,},{,},{,},{,-},{,-}} ;
int sum ;
int m,n ; void DFS(int x,int y)
{
ch[x][y] = '*' ;
for(int i = ; i < ; i++)
{
int xx = x + dir[i][] ;
int yy = y + dir[i][] ;
if(xx >= && xx <= m && yy >= && yy <= n && ch[xx][yy] == '@')
{
DFS(xx,yy) ;
}
}
}
int main()
{ while(~scanf("%d %d",&m,&n))
{
if(m == ) break ;
for(int i = ; i < m ; i++)
scanf("%s",ch[i]) ;
sum = ;
for(int i = ; i < m ; i++)
for(int j = ; j < n ; j++)
{
if(ch[i][j] == '@')
{
DFS(i,j) ;
sum++ ;
}
}
printf("%d\n",sum) ;
}
return ;
}
POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)的更多相关文章
- ZOJ 1709 Oil Deposits(dfs,连通块个数)
Oil Deposits Time Limit: 2 Seconds Memory Limit: 65536 KB The GeoSurvComp geologic survey compa ...
- HDU 1241 Oil Deposits --- 入门DFS
HDU 1241 题目大意:给定一块油田,求其连通块的数目.上下左右斜对角相邻的@属于同一个连通块. 解题思路:对每一个@进行dfs遍历并标记访问状态,一次dfs可以访问一个连通块,最后统计数量. / ...
- hdu 1241 Oil Deposits(DFS求连通块)
HDU 1241 Oil Deposits L -DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & ...
- UVA 572 -- Oil Deposits(DFS求连通块+种子填充算法)
UVA 572 -- Oil Deposits(DFS求连通块) 图也有DFS和BFS遍历,由于DFS更好写,所以一般用DFS寻找连通块. 下述代码用一个二重循环来找到当前格子的相邻8个格子,也可用常 ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDOJ/HDU 1241 Oil Deposits(经典DFS)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
- [C++]油田(Oil Deposits)-用DFS求连通块
[本博文非博主原创,均摘自:刘汝佳<算法竞赛入门经典>(第2版) 6.4 图] [程序代码根据书中思路,非独立实现] 例题6-12 油田(Oil Deposits,UVa572) 输入一个 ...
- Oil Deposits(DFS连通图)
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- 【HDU - 1241】Oil Deposits(dfs+染色)
Oil Deposits Descriptions: The GeoSurvComp geologic survey company is responsible for detecting unde ...
随机推荐
- 创建Mysql 序列
create table sequence( name ) not null primary key, current_value , increment , max_value BIGINT, -- ...
- 【HTML 5或CSS3入门教程】找兼职撰写人才
出版社要出版一套HTML 5和CSS 3方向的图书,目前急缺两名写作人员,要求1.熟悉CSS 3的各种属性,或熟悉HTML 5框架2.熟悉各种CSS代码,或熟悉各种HTML 5代码3.有写作的兴趣爱好 ...
- eclispe 出现超内纯错误
刚开始以为只要修改tomcat的最大最小内存就可以,结果还是报错,后来才懂需要在eclipse.ini文件中修改 -Xms256m-Xmx512m的值改大些,增加虚拟机运行的内存空间 刚开始最小值只有 ...
- 限制SSH访问源,禁止4A之外的地址跳转访问
[fuel节点] 在/etc/hosts.allow文件中添加: sshd:10.129.0.1:allow sshd:10.129.0.2:allow sshd:10.129.0.3:allow s ...
- ios水果风暴游戏源码下载
游戏源码是从那个IOS教程网IOS.662p.com分享给大家的. 这是一款ios水果风暴游戏源码下载,介绍给大家一下,喜欢的朋友可以下载学习一下吧.应用介绍:这是一个以获得高分和挑战更高难度为目的的 ...
- Mysql 数据库安装配置
MySQL的多种安装方法 在当今的互联网企业,Mysql数据服务几乎都是运行在LINUX系统操作系统上,当然你也可以在WINDOWS.UNIX等商业操作系统上运行. 但是一般企业都会采用LNMP.LA ...
- style、currentStyle、getComputedStyle区别介绍
style.currentStyle.getComputedStyle区别介绍 来自:蓝色天空 样式表有三种方式 内嵌样式(inline Style) :是写在Tag里面的,内嵌样式只对所有的Tag有 ...
- 《编写高质量代码-Web前端开发修改之道》笔记--第三章 高质量的HTML
本章内容: 标签的语义 为什么要使用语义化标签 如何确定你的标签是否语义良好 常见模块你真的很了解吗 标签的语义 HTML标签的设计都是有语义考虑的,部分标签的中文翻译图示及本章内容参看:3.1 标签 ...
- StringBuilder的Append()方法会比+=效率高
StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id from " + databa ...
- Swift - 手势识别
override func viewDidLoad() { super.viewDidLoad() var swipeRight = UISwipeGestureRecognizer(target: ...