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 ...
随机推荐
- Microsoft Dynamics CRM 2011的组织服务中的RetrieveMultiple方法(转)
本篇文章,介绍Microsoft Dynamics CRM 2011的组织服务中的RetrieveMultiple方法. RetreiveMultiple方法,用于获取实体的多个实例,该方法的签名如下 ...
- 选用 get 与 post 的一些建议
1.http的请求方法:get post 2. get:会把请求的内容 放到链接地址里面(数据请求的时候 默认的是get请求) 例:www.baidu.com/user/login?userna ...
- LINQ(隐式表达式、lambda 表达式)
.NET 中一项突破性的创新是 LINQ(Language Integrated Query,语言集成查询),这组语言扩展让你能够不必离开舒适的 C# 语言执行查询. LINQ 定义了用于构建查询表达 ...
- BT之下拉菜单
<div class="dropdown"> <button class="btn btn-default dropdown-toggle" ...
- SQLite学习心得
SQLite是一款很有名气的小型开源跨平台数据库,作为目前最流行的开源嵌入式关系型数据库,在系统结构设计中正在扮演着越来越重要的角色. 本文主要沿着 http://www.cppblog.com/we ...
- 增加用户为SiteCollection的管理员
1.SiteSettings-->Site collection administrators --> 增加你需要的用户
- 获取客户端访问的ip地址
function real_ip() { static $realip = NULL; if ($realip !== NULL) { return $realip; } if (isset($_SE ...
- Websocket协议之php实现
前面学习了HTML5中websocket的握手协议.打开和关闭连接等基础内容,最近用php实现了与浏览器websocket的双向通信.在学习概念的时候觉得看懂了的内容,真正在实践过程中还是会遇到各种问 ...
- vs2010配备boost编程环境
vs2010配备boost编程环境 vs2010配置boost编程环境 第一步:下载boost,我下载的方法是从http://www.boost.org/上找最新的下载.名字叫boost_1_53_0 ...
- SQLite3中自增主键
SQLite清空表并将自增列归零 SQL标准中有TRUNCATE TABLE语句,用来清空表的所有内容. 但SQLite不支持这个语句.在SQLite中直接使用 DELETE FROM TableNa ...