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的更多相关文章
-
[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 ...
-
LeetCode 675. Cut Off Trees for Golf Event
原题链接在这里:https://leetcode.com/problems/cut-off-trees-for-golf-event/description/ 题目: You are asked to ...
-
[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 ...
-
[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 ...
-
675. Cut Off Trees for Golf Event
// Potential improvements: // 1. we can use vector<int> { h, x, y } to replace Element, sortin ...
-
[LeetCode] 675. Cut Off Trees for Golf Event_Hard tag: BFS
You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-nega ...
-
[LeetCode] Minimum Height Trees 最小高度树
For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...
-
Christmas Trees, Promises和Event Emitters
今天有同事问我下面这段代码是什么意思: var MyClass = function() { events.EventEmitter.call(this); // 这行是什么意思? }; util.i ...
-
LeetCode Minimum Height Trees
原题链接在这里:https://leetcode.com/problems/minimum-height-trees/ 题目: For a undirected graph with tree cha ...
随机推荐
-
NeuSoft(2)添加系统调用
1.下载内核 apt-get install linux-source 在/usr/src下 2.解压内核 cd /usr/src tar -jxvf linux-source-3.2.0.tar.b ...
-
Advanced Packaging Tool
https://en.wikipedia.org/wiki/Advanced_Packaging_Tool Eventually, a new team picked up the project, ...
-
课堂所讲整理:HTML--7JavaScript的DOM操作
1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型:文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西. 2.Window对象操作 一.属性和方法: 属性(值或者子对象): op ...
-
Oracle获取表结构信息:表名、是否视图、字段名、类型、长度、非空、主键
select a.TABLE_NAME as "TableName", then 'V' else 'U'end as "TableType", a.COLUM ...
-
Coroutine,你究竟干了什么?
一 引子 使用Unity已经有一段时间了,对于Component.GameObject之类的概念也算是有所了解,而脚本方面从一开始就选定了C#,目前来看还是挺明智的:Boo太小众,而且支持有限:JS( ...
-
Java虚拟机说明书
JVM运行原理: Class的加载 过程:加载-验证-准备-解析-初始化-执行-卸载 加载:class文件(二进制字节流)被类加载器加载到内存中,将这个字节流所代表的静态存储结构转化为方法区的运行时数 ...
-
tmux 后台训练
参考链接:https://blog.csdn.net/u014381600/article/details/54588531
-
基于 __new__ 方法的单例模式
单例模式定义 首次实例化创建实例化对象 之后的每次实例化都用最初的实例化对象 即单实例模式 __new__ 的原理 __new__ 方法可以在 __init__ 方法执行 这样可以在初始化之前进行一系 ...
-
Git在eclipse中的使用,克隆导入eclipse项目
一 Eclipse 安装EGit 1)安装 Eclipse Juno 版后已经集成了EGit,可以通过如下地址安装:http://download.eclipse.org/egit/upda ...
-
Libreoffice 各类文件转换的filtername
LIBREOFFICE_DOC_FAMILIES = [ "TextDocument", "WebDocument", "Spreadsheet&qu ...