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 ...
随机推荐
- beautifulsoup4进阶学习笔记
requests库是可以找到想要的东西,基本上几行代码就搞定,但是进一步把有用的内容提取出来变成自己想要的格式来方便后续进行数据分析 正则表达式提取的话,需要一些时间成本,这个可以每天积累一点. 这里 ...
- 使用git将本地项目上传至git仓库
个人博客 地址:https://www.wenhaofan.com/article/20190508220440 介绍 一般来说开发过程中都是先在git创建远程仓库,然后fetch到本地仓库,再进行c ...
- JavaDay2(中)
Java循环与分支练习 习题1: 输出1~100内前5个可以被3整除的数. public class Day2_Test1 { //输出1~100内前5个可以被3整除的数. public static ...
- JS使用知识点理解
var keyValue = $.request("keyValue"); $(function () { ////修改页面select下拉选框js $("#BloodB ...
- Java中8进制数和16进制数的表示方法
由于数据在计算机中的表示,最终以二进制的形式存在,所以有时候使用二进制,可以更直观地解决问题. 但,二进制数太长了.比如int 类型占用4个字节,32位.比如100,用int类型的二进制数表达将 ...
- PP: Learning representations for time series clustering
Problem: time series clustering TSC - unsupervised learning/ category information is not available. ...
- createElement(九)
Vue.js 利用 createElement 方法创建 VNode,它定义在 src/core/vdom/create-elemenet.js 中: // wrapper function for ...
- RN开发-Flex
1.容器属性 (1). display : flex | inline-flex (块级伸缩容器 | 行内级伸缩容器) (2). flex-direction : row ...
- 解读Ubuntu的sources.list 和soucres.litsd
使用过Ubuntu的道友们都知道,默认地址是乌班图的org 配置的,对于国内长途跋涉的各位高手来讲真是艰辛: 所以我们一般在安装的时候会先修改服务器源地址使用国内的比如ali,清华或者华为的 源文件地 ...
- orm 相关
优化