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 ...
 
随机推荐
- 使用Emmet(前身Zen Coding)加速Web前端开发
			
Emmet插件以前被称作为Zen Coding,是一个文本编辑器的插件,它可以帮助您快速编写HTML和CSS代码,从而加速Web前端开发.早在2009年,Sergey Chikuyonok写过一篇文章 ...
 - 利用图层的mask属性裁剪图形
			
需求如上图. 代码如下 //充值 UIButton *rechargeButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )]; [re ...
 - MySQL数据库的登陆
			
MySQL数据库的登陆 MySQL是一种C/S结构. C/S(Client/Server)客户端/服务器 MySQL的客户端: 1.cmd客户端 2.可视化图形界面 3.php代码 登陆: MySQL ...
 - header函数
			
header函数 主要用于对http协议头设置相关信息 设置浏览器显示编码(解决乱码) header("Content-type:text/html;charset=utf-8") ...
 - C#中调用unmanaged DLL
			
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
 - asp.net 时间比较,常用于在某段时间进行操作
			
DateTime.Compare(t1,t2)比较两个日期大小,排前面的小,排在后面的大,比如:2011-2-1就小于2012-3-2返回值小于零: t1 小于 t2. 返回值等于零 : t1 等于 ...
 - DTCMS,手机网站访问跳转到DTCMS官网解决方法
			
mobile\js\base.js main\js\common.js 去掉location.href = 'http://m.dtcms.net'; 也可以设定手机访问跳转到指定域名
 - javascript常用对象
			
A,window对象 window对象是浏览器模型对象的顶层对象 常用属性: screen:客户端的屏幕和显示性能的信息. history:客户端访问过的url信息 location:当前url链接的 ...
 - Openvpn完美解决公司网络没有固定公网IP的问题
			
方案背景: 公司办公网络使用长城宽带上网有一段时间了,有4个固定IP(2个电信,2个网通),链路不太稳定,经常有问题,因此考虑取消长城宽带,采用原来的adsl上网.但是有个问题,因为公司内网有几台服务 ...
 - cxgrid  footer summary value by a column
			
var AIndex: integer; AValue: variant; begin with cxGrid1DBTableView1.DataController.Summary do begin ...