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-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 ...
随机推荐
- UVa 3602 - DNA Consensus String 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- Five Great .NET Framework 4.5 Features (五大特性)
[译].Net 4.5 的五项强大新特性 本文原文:Five Great .NET Framework 4.5 Features译者:冰河魔法师 目录 介绍 特性一:async和await 特性二 ...
- 常见的SQLALCHEMY列类型
常见的SQLALCHEMY列类型.配置选项和关系选项 类型名称 python类型 描述 Integer int 常规整形,通常为32位 SmallInteger int 短整形, ...
- :模板方法模式:Beverage
#ifndef __COFFINEBEVERAGE_H__ #define __COFFINEBEVERAGE_H__ #include <iostream> using namespac ...
- loadrunner json中文无法识别问题
http://blog.sina.com.cn/s/blog_6ff7a3b50101awmy.html
- Android开发 ---基本UI组件3:单选按钮、多选按钮、下拉列表、提交按钮、重置按钮、取消按钮
Android开发 ---基本UI组件2 1.activity_main.xml 描述: 定义一个用户注册按钮 <?xml version="1.0" encoding=&q ...
- 一次练习 发现的问题,malloc free 无效;findfirstfile失败,writefile失败的原因
#include <windows.h> #include <stdio.h> #include <shlwapi.h> #pragma comment(lib,& ...
- points from ZhiQIng Hu
1,The errors in vertical direction are about 3 times horizontal errors of GPS data. But the precisio ...
- C点滴成海------Ubuntu怎么运行C语言
Ubuntu怎么运行C语言 一.安装相关软件 安装vim:输入 sudo apt-get install vim: 安装gcc:输入 sudo apt-get install g++. 二.编写代码 ...
- Python 通过队列实现一个生产者消费者模型
import time from multiprocessing import Process,Queue #生产者 def producer(q): for i in range(10): time ...