题目链接:http://ac.jobdu.com/problem.php?pid=1460

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

//
// 1460 Oil Deposit.cpp
// Jobdu
//
// Created by PengFei_Zheng on 23/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#define MAX_SIZE 101 using namespace std; char plot[MAX_SIZE][MAX_SIZE];
bool visited[MAX_SIZE][MAX_SIZE];
int change[][]={{-,-,-,,,,,},{-,,,-,,-,,}}; int n, m; void DFS(int x, int y){
for(int i = ; i < ; i++){
int nx = x + change[][i];
int ny = y + change[][i];
if(nx< || nx>=n || ny< || ny>=m) continue;
if(plot[nx][ny]=='*') continue;
if(visited[nx][ny]==true) continue;
visited[nx][ny]=true;
DFS(nx,ny);
}
return;
}
int main(){
// for(int i = 0 ; i < 8 ; i ++){
// cout<<"change[0]["<<i<<"] = "<<change[0][i]<<" ";
// cout<<"change[1]["<<i<<"] = "<<change[1][i]<<endl;
// }
while(scanf("%d%d",&n,&m)!=EOF){
if(==n && ==m) break; for(int i = ; i < n ; i++){
scanf("%s",plot[i]);
} for(int i = ; i < n ; i ++){
for(int j = ; j < m ; j++){
visited[i][j]=false;
}
}
int ans = ;
for(int i = ; i < n ; i++){
for(int j = ; j < m ; j++){
if(visited[i][j]==true) continue;
if(plot[i][j]=='*') continue;
DFS(i,j);
ans++;
}
}
printf("%d\n",ans);
}
return ;
}
/**************************************************************
Problem: 1460
User: zpfbuaa
Language: C++
Result: Accepted
Time:10 ms
Memory:1540 kb
****************************************************************/

题目1460:Oil Deposit(递归遍历图)的更多相关文章

  1. Python 非递归遍历图

    class Queue: def __init__(self,max_size): self.max_size = int(max_size) self.queue = [] def put(self ...

  2. 九度oj 题目1460:Oil Deposit

    题目描述: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...

  3. 面试题目——《CC150》树与图

    面试题4.1:实现一个函数,检查二叉树是否平衡.在这个问题中,平衡树的定义如下:任意一个结点,其两颗子树的高度差不超过1. 思路:两个方法,第一种速度较快 package cc150; public ...

  4. UVa 10562 Undraw the Trees(递归遍历)

    题目链接: https://cn.vjudge.net/problem/UVA-10562 Professor Homer has been reported missing. We suspect ...

  5. 数据结构二叉树的递归与非递归遍历之java,javascript,php实现可编译(1)java

    前一段时间,学习数据结构的各种算法,概念不难理解,只是被C++的指针给弄的犯糊涂,于是用java,web,javascript,分别去实现数据结构的各种算法. 二叉树的遍历,本分享只是以二叉树中的先序 ...

  6. 深度-first遍历图--邻接表实现

    在这里,邻接表的实现与深度优先遍历图,使用递归. #include<iostream> using namespace std; #define VERTEXNUM 5//结点数 stru ...

  7. Oil Deposit

    题目描述: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. ...

  8. Java中递归的优缺点,Java写一个递归遍历目录下面的所有文件包括子文件夹里边的文件。

    题目: 遍历出aaa文件夹下的文件 首先分析思路: 1.首先判断这个文件夹是否为文件,通过isFile()函数可以判断是否为文件. 2.然后通过isDirectory判断是否为目录. 3.如果是目录就 ...

  9. 144.Binary Tree Preorder Traversal---二叉树先序、中序非递归遍历

    题目链接 题目大意:返回二叉树的先序遍历list.中序见94,后序见145. 法一:普通递归遍历,只是这里多了一个list数组,所以分成了两个函数.代码如下(耗时1ms): public List&l ...

随机推荐

  1. win10 禁用Defender

    cmd reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" /v "Dis ...

  2. C# 大图片压缩算法,减少图片体积

    声明: 图片压缩算法,不建议对小图片进行压缩,一般文件小于1m的,真心没必要压缩, 图片很小的,例如:几百KB的图片,有可能不会减少图片体积,反而压缩后更大,也很正常, 请大家合理使用,并不是,所有图 ...

  3. JavaSE(二)之继承、封装、多态

    学习完类与对象终于认识到什么是类,什么是对象了.接下来要看的就是java的三大特征:继承.封装.多态. 一.封装(数据的隐藏) 在定义一个对象的特性的时候,有必要决定这些特性的可见性,即哪些特性对外部 ...

  4. linux下redis的安装和集群搭建

    一.redis概述 1.1.目前redis支持的cluster特性: 1):节点自动发现. 2):slave->master 选举,集群容错. 3):Hot resharding:在线分片. 4 ...

  5. Android布局学习——android:gravity和android:layout_gravity的区别

    [Android布局学习系列]   1.Android 布局学习之——Layout(布局)详解一   2.Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)   3.And ...

  6. ADCD 1.9 ZOS 配置 CTCI-W32 TCPIP 网络

    试验步骤:两步走,第一步修改Hercules的配置文件 在hercules 配置文件末尾加上    0E20-0E21 CTCI     -n 0A-00-27-00-00-00  192.168.5 ...

  7. 修改linux终端DIR显示颜色

    头疼死,linux终端下,目录颜色蓝色在黑色的背景下,睁大双眼都看不清楚. 找办法修改,找到默认的颜色设置目录: # vi /etc/DIR_COLORS 查看文件,并查找DIR: 可以看到默认设定“ ...

  8. Android 内存

    memory usage of this progress under 15MB for 1GB RAM device Android内存机制分析下篇:分析APP内存使用情况http://mobile ...

  9. WPF - How to force a Command to re-evaluate 'CanExecute' via its CommandBindings

    Not the prettiest in the book, but you can use the CommandManager to invalidate all commandbinding: ...

  10. 分享一个有趣的代码,调用电脑中的api语音

    在文本文件中输入如下代码: set objTTS = CreateObject("sapi.spvoice") objTTS.speak("为啥我对象这么闹呢?" ...