1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-25 06:48:57 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个下标从 <strong>0</strong>&nbsp;开始的二维整数数组&nbsp;<code>grid</code>&nbsp;,它的大小为&nbsp;<code>m x n</code>&nbsp;,表示一个商店中物品的分布图。数组中的整数含义为:</p>\n\n<ul>\n\t<li><code>0</code>&nbsp;表示无法穿越的一堵墙。</li>\n\t<li><code>1</code>&nbsp;表示可以自由通过的一个空格子。</li>\n\t<li>所有其他正整数表示该格子内的一样物品的价格。你可以自由经过这些格子。</li>\n</ul>\n\n<p>从一个格子走到上下左右相邻格子花费&nbsp;<code>1</code>&nbsp;步。</p>\n\n<p>同时给你一个整数数组&nbsp;<code>pricing</code> 和&nbsp;<code>start</code>&nbsp;,其中&nbsp;<code>pricing = [low, high]</code> 且&nbsp;<code>start = [row, col]</code>&nbsp;,表示你开始位置为&nbsp;<code>(row, col)</code>&nbsp;,同时你只对物品价格在<strong>&nbsp;闭区间</strong>&nbsp;<code>[low, high]</code>&nbsp;之内的物品感兴趣。同时给你一个整数&nbsp;<code>k</code>&nbsp;。</p>\n\n<p>你想知道给定范围 <strong>内</strong>&nbsp;且 <strong>排名最高</strong>&nbsp;的 <code>k</code>&nbsp;件物品的 <strong>位置</strong>&nbsp;。排名按照优先级从高到低的以下规则制定:</p>\n\n<ol>\n\t<li>距离:定义为从&nbsp;<code>start</code>&nbsp;到一件物品的最短路径需要的步数(<strong>较近</strong>&nbsp;距离的排名更高)。</li>\n\t<li>价格:<strong>较低</strong>&nbsp;价格的物品有更高优先级,但只考虑在给定范围之内的价格。</li>\n\t<li>行坐标:<strong>较小</strong>&nbsp;行坐标的有更高优先级。</li>\n\t<li>列坐标:<strong>较小</strong>&nbsp;列坐标的有更高优先级。</li>\n</ol>\n\n<p>请你返回给定价格内排名最高的 <code>k</code>&nbsp;件物品的坐标,将它们按照排名排序后返回。如果给定价格内少于 <code>k</code>&nbsp;件物品,那么请将它们的坐标&nbsp;<strong>全部</strong>&nbsp;返回。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/16/example1drawio.png\" style=\"width: 200px; height: 151px;\"></p>\n\n<pre><b>输入:</b>grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3\n<b>输出:</b>[[0,1],[1,1],[2,1]]\n<b>解释:</b>起点为 (0,0) 。\n价格范围为 [2,5] ,我们可以选择的物品坐标为 (0,1)(1,1)(2,1) 和 (2,2) 。\n这些物品的排名为\n- (0,1) 距离为 1\n- (1,1) 距离为 2\n- (2,1) 距离为 3\n- (2,2) 距离为 4\n所以给定价格范围内排名最高的 3 件物品的坐标为 (0,1)(1,1) 和 (2,1) 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/16/example2drawio1.png\" style=\"width: 200px; height: 151px;\"></p>\n\n<pre><b>输入:</b>grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2\n<b>输出:</b>[[2,1],[1,2]]\n<b>解释:</b>起点为 (2,3) 。\n价格范围为 [2,3] ,我们可以选择的物品坐标为 (0,1)(1,1)(1,2) 和 (2,1) 。\n这些物品的排名为 \n- (2,1) 距离为 2 ,价格为 2\n- (1,2) 距离为 2 ,价格为 3\n- (1,1) 距离为 3\n- (0,1) 距离为 4\n所以给定价格范围内排名最高的 2 件物品的坐标为 (2,1) 和 (1,2) 。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/30/example3.png\" style=\"width: 149px; height: 150px;\"></p>\n\n<pre><b>输入:</b>grid = [[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3\n<b>输出:</b>[[2,1],[2,0]]\n<b>解释:</b>起点为 (0,0) 。\n价格范围为 [2,3] ,我们可以选择的物品坐标为 (2,0) 和 (2,1) 。\n这些物品的排名为\n- (2,1) 距离为 5\n- (2,0) 距离为 6\n所以给定价格范围内排名最高的 2 件物品的坐标为 (2,1) 和 (2,0) 。\n注意k = 3 但给定价格范围内只有 2 件物品。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>m == grid.length</code></li>\n\t<li><code>n == grid[i].length</code></li>\n\t<li><code>1 &lt;= m, n &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= m * n &lt;= 10<sup>5</sup></code></li>\n\t<li><code>0 &lt;= grid[i][j] &lt;= 10<sup>5</sup></code></li>\n\t<li><code>pricing.length == 2</code></li>\n\t<li><code>2 &lt;= low &lt;= high &lt;= 10<sup>5</sup></code></li>\n\t<li><code>start.length == 2</code></li>\n\t<li><code>0 &lt;= row &lt;= m - 1</code></li>\n\t<li><code>0 &lt;= col &lt;= n - 1</code></li>\n\t<li><code>grid[row][col] &gt; 0</code></li>\n\t<li><code>1 &lt;= k &lt;= m * n</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 16,
"likes": 18,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -161,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"3K\", \"totalSubmission\": \"7.8K\", \"totalAcceptedRaw\": 3003, \"totalSubmissionRaw\": 7817, \"acRate\": \"38.4%\"}",
"stats": "{\"totalAccepted\": \"3.1K\", \"totalSubmission\": \"8.1K\", \"totalAcceptedRaw\": 3116, \"totalSubmissionRaw\": 8077, \"acRate\": \"38.6%\"}",
"hints": [
"Could you determine the rank of every item efficiently?",
"We can perform a breadth-first search from the starting position and know the length of the shortest path from start to every item.",