题目链接: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. CSS3和jQuery实现的自定义美化Checkbox和Radiobox

    现在经常可以在网络上看到一些非常奇特的表单元素,例如Checkbox复选框和Radiobox单选框,浏览器默认的样式确实是太丑了,而且更让人蛋疼的是各个浏览器的样式还不统一,考虑到现在越来越多的用户使 ...

  2. thinkphp 外部js语言包

    Thinkphp php文件也外部js文件公用同一个语言包 一 . php语言包转json数据格式 1.新建验证字段的语言包 application\common\lang\validate-cn.p ...

  3. python 在windows 中文显示

    今天看到mechanize,在网上找例子实验,发现只要代码里出现中文,就会报错 SyntaxError: Non-ASCII character , but no encoding declared; ...

  4. VC++ 链接错误LINK : fatal error LNK1104: cannot open file "*.lib"

    问题描述: 运行VC++编译时经常出现 Linking… LINK : fatal error LNK1104: cannot open file “*.lib” Error executing li ...

  5. 防止dedecms注入文件挂马的解决方法

    1.目录权限我们不建议用户把栏目目录设置在根目录,原因是这样进行安全设置会十分的麻烦,在默认的情况下,安装完成后,目录设置如下:(1) data.templets.uploads.a或5.3的html ...

  6. 排列2(全排列next_permutation 注意格式)

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  7. layui文件上传进度条(模拟)

    1.修改上传组件js(没测) https://blog.csdn.net/weixin_42457316/article/details/81017471 https://www.cnblogs.co ...

  8. 8 -- 深入使用Spring -- 3...1 Resource实现类InputStreamResource、ByteArrayResource

    8.3.1 Resource实现类------InputStreamResource:访问输入流资源的实现类.ByteArrayResource:访问字节数组资源的实现类. 5. 访问字节数组资源 ⊙ ...

  9. Jquery Ajax 和json用法

    向您的页面添加 jQuery 库 jQuery 库位于一个 JavaScript 文件中,其中包含了所有的 jQuery 函数. 可以通过下面的标记把 jQuery 添加到网页中: <head& ...

  10. swift--CATransform3D的简单介绍

    今天来了解下CATransform3D的一些基本的知识.CATransform3D是一个用于处理3D形变的类,其可以改变控件的平移.缩放.旋转.斜交等,其坐标系统采用的是三维坐标系,即向右为x轴正方向 ...