Virtual Judge HDU 1241 Oil Deposits
八方向 深搜
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
char maps[][];
int n,m,d[]= {-,-,-,, , ,,};
int z[]= {-, , ,-,,-,,}; //8个方向
void dfs(int x, int y) {
maps[x][y] = '*'; //变为*,相当于走过
for (int i = ; i < ; i++) {
int nx = x + d[i], ny = y + z[i];
if (<=nx&&nx<m&&<=ny&&ny<n) {
if (maps[nx][ny]=='@') {
dfs(nx, ny);
}
}
}
}
int main() {
while(~scanf("%d%d", &m, &n)&&(m || n)) {
int count = ;
for(int i = ; i < m; i++)
scanf("%s", maps[i]);
for(int i = ; i < m; i++)
for(int j = ; j < n; j++) {
if(maps[i][j]=='@') {
dfs(i,j);
count++;
}
}
printf("%d\n", count);
}
return ;
}
Virtual Judge HDU 1241 Oil Deposits的更多相关文章
- DFS(连通块) HDU 1241 Oil Deposits
题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...
- 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 & ...
- HDU 1241 Oil Deposits(石油储藏)
HDU 1241 Oil Deposits(石油储藏) 00 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Probl ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU 1241 Oil Deposits DFS(深度优先搜索) 和 BFS(广度优先搜索)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 1241 Oil Deposits (DFS/BFS)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDOJ/HDU 1241 Oil Deposits(经典DFS)
Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...
随机推荐
- Python_基础数据类型
一,首先介绍一下变量 1. 变量是什么 在Python中,变量的概念基本上和初中代数的方程变量是一致的. 2. 变量命名规则 由数字.字母.下划线组成 不能以数字开头 要具有描述性 要区分大小写 禁止 ...
- ES6扩展
模板字符串和标签模板 const getCourseList = function() { // ajax return { status: true, msg: '获取成功', data: [{ i ...
- win10子系统ubuntu忘记密码解决方案
准备部署一个rocket.chat 需要安装mongodb 3.6 准备直接在子系统中安装一下,结果忘记ROOT密码了 找了一下子系统重置密码 记录如下 ubuntu config --defau ...
- python常见函数积累
shape() 返回数组或者数据框有多少行或者多少列 import numpy as np x = np.array([[1,2,5],[2,3,5],[3,4,5],[2,3,6]]) #输出数组的 ...
- 为什么重写equals方法,还必须要重写hashcode方法
一.equals方法和hashcode的关系 根据Object.hashCode的通用约定: 如果两个对象相同(equals方法返回true),那么hashcode也相等.(图1) 如果两个对象的ha ...
- 提取 Microsoft.ReportViewer等dll
ReportViewer 在开发环境没问题 发布以后可能会提示找不到 Microsoft.ReportViewer 下的几个dll 可以用用下面脚本在开发服务器上提取 相应的dll @SET dest ...
- Wannafly Camp 2020 Day 2D 卡拉巴什的字符串 - 后缀自动机
动态维护任意两个后缀的lcp集合的mex,支持在串末尾追加字符. Solution 考虑在 SAM 上求两个后缀的 LCP 的过程,无非就是找它们在 fail 树上的 LCA,那么 LCP 长度就是这 ...
- 看完它,你就全懂了十大Wifi芯片原厂!
看完它,你就全懂了十大Wifi芯片原厂! 来源:全球物联网观察 概要:不知不觉中,WiFi几乎已攻占了整个世界.现在只要你上网,可能就离不开WiFi了. 2014年是物联网WiFi市场关键的转折期 ...
- pymysql 连接池
pymysql连接池 import pymysql from DBUtils.PooledDB import PooledDB, SharedDBConnection ''' 连接池 ''' clas ...
- 【巨杉数据库SequoiaDB】巨杉再获企业级认可,分布式数据库领跑“一亿中流”
据全球最具权威的IT研究与顾问咨询公司 Gartner 预测,DBMS(数据库管理系统)市场从2017年到2018年增长了18.4%,达到461亿美元,这是有史以来最大幅的增长,并有望在2019年超过 ...