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

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

参考代码:

  1. //
  2. // 1460 Oil Deposit.cpp
  3. // Jobdu
  4. //
  5. // Created by PengFei_Zheng on 23/04/2017.
  6. // Copyright © 2017 PengFei_Zheng. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <iostream>
  11. #include <algorithm>
  12. #include <string.h>
  13. #include <cmath>
  14. #define MAX_SIZE 101
  15.  
  16. using namespace std;
  17.  
  18. char plot[MAX_SIZE][MAX_SIZE];
  19. bool visited[MAX_SIZE][MAX_SIZE];
  20. int change[][]={{-,-,-,,,,,},{-,,,-,,-,,}};
  21.  
  22. int n, m;
  23.  
  24. void DFS(int x, int y){
  25. for(int i = ; i < ; i++){
  26. int nx = x + change[][i];
  27. int ny = y + change[][i];
  28. if(nx< || nx>=n || ny< || ny>=m) continue;
  29. if(plot[nx][ny]=='*') continue;
  30. if(visited[nx][ny]==true) continue;
  31. visited[nx][ny]=true;
  32. DFS(nx,ny);
  33. }
  34. return;
  35. }
  36. int main(){
  37. // for(int i = 0 ; i < 8 ; i ++){
  38. // cout<<"change[0]["<<i<<"] = "<<change[0][i]<<" ";
  39. // cout<<"change[1]["<<i<<"] = "<<change[1][i]<<endl;
  40. // }
  41. while(scanf("%d%d",&n,&m)!=EOF){
  42. if(==n && ==m) break;
  43.  
  44. for(int i = ; i < n ; i++){
  45. scanf("%s",plot[i]);
  46. }
  47.  
  48. for(int i = ; i < n ; i ++){
  49. for(int j = ; j < m ; j++){
  50. visited[i][j]=false;
  51. }
  52. }
  53. int ans = ;
  54. for(int i = ; i < n ; i++){
  55. for(int j = ; j < m ; j++){
  56. if(visited[i][j]==true) continue;
  57. if(plot[i][j]=='*') continue;
  58. DFS(i,j);
  59. ans++;
  60. }
  61. }
  62. printf("%d\n",ans);
  63. }
  64. return ;
  65. }
  66. /**************************************************************
  67. Problem: 1460
  68. User: zpfbuaa
  69. Language: C++
  70. Result: Accepted
  71. Time:10 ms
  72. Memory:1540 kb
  73. ****************************************************************/

题目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. MyBatis中对于字符串blank(null、empty)的判定方法

    直接上代码,关键需要进行2个判定,一个是null判定,一个是 ‘’ 判定. <where> <if test="url!= null and url!=''"&g ...

  2. thinkphp 配置加载

    状态配置 每个应用都可以在不同的情况下设置自己的状态(或者称之为应用场景),并且加载不同的配置文件. 举个例子,你需要在公司和家里分别设置不同的数据库测试环境.那么可以这样处理,在公司环境中,我们在入 ...

  3. ASP.NET C# 登陆窗体 限制用户名只输入字母 数字以及下划线

    文本框的输入限制,我们主要集中两个问题: 一.怎样限制用户名输入的长度? 答:设置txtName的属性 MaxLength="; (我们这里以10个字符为例) 二.怎样限制用户名只输入字母 ...

  4. java获取map中的最小KEY,最小VALUE

    import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Map ...

  5. nginx反向代理配置(nginx.conf+proxy_set_header)

    转载:https://blog.csdn.net/bjsunwei/article/details/62231209 location / { proxy_pass http://test; prox ...

  6. 【原】list<T>排序

    继承IComparable #region IComparable        public int CompareTo(object  obj)    {        if(obj is Sce ...

  7. Maven -- 发布jar包至远程仓库

    啦啦啦

  8. 5 -- Hibernate的基本用法 --1 3 流行的ORM框架简介

    ⊙ JPA : JPA本身只是一种ORM规范,并不是ORM产品.它是Java EE规范制定者向开源世界学习的结果.JPA实体与Hibernate PO十分相似,甚至JPA实体完全可作为Hibernat ...

  9. Linux od命令(以指定进制显示文件)

    从“读取二进制文件”出发,到od命令的使用 在桃村实习期间,一直努力做毕业设计,我的毕业设计中有一个内容就是读取SEGY文件.在读取文件时,经常遇到的问题时你要读取浮点型数据,这时你就必须考虑你所使用 ...

  10. Websphere安装配置与项目部署

    0x01 下载安装 1.在IBM官网下载安装包 打开下载地址,需注册账户,登录后,选择Windows 64-bit下载 2.解压缩,运行install.exe文件 3.输入刚才注册的用户名和密码,并输 ...