题目链接: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. js 形如 "1,2,3"的操作

    查找指定元素在数组中的index. var arr=[1,2,3]; $.inArray(2, arr);//返回1 arr.splice($.inArray(2, arr),1); //从数组中删除 ...

  2. 设置时间同步(Linux,Solaris)

    经过网上各种搜索,将LINUX平台及solaris平台的时间同步整理如下: 主机情况:应用:2台LINUX服务器 redhat 5.5 内网数据库:2台Solaris服务器 Solaris 10 内网 ...

  3. 系统目录结构/ls命令/文件类型/alias命令

    2.1/2.2 系统目录结构 2.3 ls命令 2.4 文件类型 2.5 alias命令 linux文件目录结构 linux文件结构 / 系统跟目录 root  root用户主目录,存放启动linux ...

  4. winform利用itextsharp.dll实现图片文件转换PDF格式文件

    1.利用itextsharp.dll实现单个图片文件转换为PDF格式文件, 可以使用以下类: void ConvertJPG2PDF(string jpgfile, string pdf) { var ...

  5. vue学习起步,vue环境安装

    vue安装的前提是安装了nodejs 安装淘宝镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org 安装webpack c ...

  6. winform下 PictureBox 显示网络图片

    Image pic = new Image.FromStream(WebRequest.Create("http://x.com/x.jpg").GetResponse().Get ...

  7. 文件流方式 删除prefab空脚本

    /// <summary> /// 删除一个Prefab上的空脚本 /// </summary> /// <param name="path"> ...

  8. while 1要小心

    之前判断一个接口的返回,一定约定好了是返回retcode 1或者retcode 0,就用的这个判断,但是接口挂了的时候,一直返回未登录,找了很长时间为什么cpu一直消耗那么高. 使用wihle 1时候 ...

  9. 字符串中包含汉字和\u,显示出汉字来

    针对py2,py3不需要这样.#coding=utf8import sysreload(sys)sys.setdefaultencoding('utf8') strx2='你好\u4e2d\u56fd ...

  10. PMP模拟考试-2

    1. Increasing resources on the critical path activities may not always shorten the length of the pro ...