题目链接: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. iOS: 自动增高的 textView

    如 iPhone 内应用“信息”的输入框一样,输入文字过多或者输入换行,输入框可以随着内容自动变化.主要是计算内容的尺寸并相应更改输入框的frame.具体表现在: 更改输入框的 frame.origi ...

  2. 查看WEB服务器的连接数

    查看WEB服务器的连接数 https://technet.microsoft.com/en-us/sysinternals/bb897437 tcpView

  3. Nginx安装 默认虚拟主机 Nginx用户认证 Nginx域名重定向

    Nginx安装 cd /usr/local/src (http://nginx.org/en/download.html) wget http://nginx.org/download/nginx-1 ...

  4. Service 保活法之二

    正确应对系统内存不足,OnLowMemory和OnTrimMemory回调 理论上,一个具备良好行为的应用应该考虑Android系统内存紧张的问题,这样有助于维持一个良好的生态.在前人的基础上,本文对 ...

  5. 使用 resizableImageWithCapInsets 方法实现可伸缩图片

    之前介绍过通过 stretchableImageWithLeftCapWidth:topCapHeight: 方法来实现可伸缩图片: 可看这篇随笔:使用 stretchableImageWithLef ...

  6. Selenium Webdriver 的 PageObject 改造

    PageObject中提供了一个@FindBy注解,也非常好用,但由于其是一次性全部初始化所有的WebElement,对于当前还不存在于页面上的Element在初始化时就会报错,为了解决这个问题,自然 ...

  7. VCL 中的 Windows API 函数(5): AlphaBlend

    AlphaBlend 是指定图像混合透明的函数, 在 Graphics.GraphUtil.RibbonStyleActnCtrls 单元用到. 下面的测试是把一张图片显示在窗体, 并可以调整透明度. ...

  8. Spring MVC异常处理详解 ExceptionHandler good

    @ControllerAdvice(basePackageClasses = AcmeController.class) public class AcmeControllerAdvice exten ...

  9. session没保存,登录失败

    今天发现做的项目,登录不上 查了下原因,原来是session没保存上 查看php.ini文件,session.save_path="D:\php\tmp\tmp" 查看了下对应的目 ...

  10. 用FileExplorer查看android手机中的数据库

    想查看一下手机中的通讯录数据库,google之后找到了办法. 参考: http://stackoverflow.com/questions/4867379/android-eclipse-ddms-c ...