LeetCode - Cut Off Trees for Golf Event

时间:2023-01-28 09:15:05
You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-negative 2D map, in this map:

0 represents the obstacle can't be reached.
1 represents the ground can be walked through.
The place with number bigger than 1 represents a tree can be walked through, and this positive number represents the tree's height.
You are asked to cut off all the trees in this forest in the order of tree's height - always cut off the tree with lowest height first. And after cutting, the original place has the tree will become a grass (value 1). You will start from the point (0, 0) and you should output the minimum steps you need to walk to cut off all the trees. If you can't cut off all the trees, output -1 in that situation. You are guaranteed that no two trees have the same height and there is at least one tree needs to be cut off. Example 1:
Input:
[
[1,2,3],
[0,0,4],
[7,6,5]
]
Output: 6
Example 2:
Input:
[
[1,2,3],
[0,0,0],
[7,6,5]
]
Output: -1
Example 3:
Input:
[
[2,3,4],
[0,0,5],
[8,7,6]
]
Output: 6
Explanation: You started from the point (0,0) and you can cut off the tree in (0,0) directly without walking.
Hint: size of the given matrix will not exceed 50x50.

我用了priorityqueue+bfs 来做,但没有得到正解,目前不知道错在哪儿。。。

LeetCode - Cut Off Trees for Golf Event的更多相关文章

  1. [LeetCode] Cut Off Trees for Golf Event 为高尔夫赛事砍树

    You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-nega ...

  2. LeetCode 675. Cut Off Trees for Golf Event

    原题链接在这里:https://leetcode.com/problems/cut-off-trees-for-golf-event/description/ 题目: You are asked to ...

  3. [LeetCode] 675. Cut Off Trees for Golf Event 为高尔夫赛事砍树

    You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-nega ...

  4. [Swift]LeetCode675. 为高尔夫比赛砍树 | Cut Off Trees for Golf Event

    You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-nega ...

  5. 675. Cut Off Trees for Golf Event

    // Potential improvements: // 1. we can use vector<int> { h, x, y } to replace Element, sortin ...

  6. &lbrack;LeetCode&rsqb; 675&period; Cut Off Trees for Golf Event&lowbar;Hard tag&colon; BFS

    You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-nega ...

  7. &lbrack;LeetCode&rsqb; Minimum Height Trees 最小高度树

    For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...

  8. Christmas Trees&comma; Promises和Event Emitters

    今天有同事问我下面这段代码是什么意思: var MyClass = function() { events.EventEmitter.call(this); // 这行是什么意思? }; util.i ...

  9. LeetCode Minimum Height Trees

    原题链接在这里:https://leetcode.com/problems/minimum-height-trees/ 题目: For a undirected graph with tree cha ...

随机推荐

  1. NeuSoft&lpar;2&rpar;添加系统调用

    1.下载内核 apt-get install linux-source 在/usr/src下 2.解压内核 cd /usr/src tar -jxvf linux-source-3.2.0.tar.b ...

  2. Advanced Packaging Tool

    https://en.wikipedia.org/wiki/Advanced_Packaging_Tool Eventually, a new team picked up the project, ...

  3. 课堂所讲整理:HTML--7JavaScript的DOM操作

    1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型:文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西. 2.Window对象操作 一.属性和方法: 属性(值或者子对象): op ...

  4. Oracle获取表结构信息&colon;表名、是否视图、字段名、类型、长度、非空、主键

    select a.TABLE_NAME as "TableName", then 'V' else 'U'end as "TableType", a.COLUM ...

  5. Coroutine,你究竟干了什么?

    一 引子 使用Unity已经有一段时间了,对于Component.GameObject之类的概念也算是有所了解,而脚本方面从一开始就选定了C#,目前来看还是挺明智的:Boo太小众,而且支持有限:JS( ...

  6. Java虚拟机说明书

    JVM运行原理: Class的加载 过程:加载-验证-准备-解析-初始化-执行-卸载 加载:class文件(二进制字节流)被类加载器加载到内存中,将这个字节流所代表的静态存储结构转化为方法区的运行时数 ...

  7. tmux 后台训练

    参考链接:https://blog.csdn.net/u014381600/article/details/54588531

  8. 基于 &lowbar;&lowbar;new&lowbar;&lowbar; 方法的单例模式

    单例模式定义 首次实例化创建实例化对象 之后的每次实例化都用最初的实例化对象 即单实例模式 __new__ 的原理 __new__ 方法可以在 __init__ 方法执行 这样可以在初始化之前进行一系 ...

  9. Git在eclipse中的使用,克隆导入eclipse项目

    一 Eclipse 安装EGit 1)安装      Eclipse Juno 版后已经集成了EGit,可以通过如下地址安装:http://download.eclipse.org/egit/upda ...

  10. Libreoffice 各类文件转换的filtername

    LIBREOFFICE_DOC_FAMILIES = [ "TextDocument", "WebDocument", "Spreadsheet&qu ...