1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/矩阵查询可获得的最大分数 [maximum-number-of-points-from-grid-queries].html

44 lines
2.1 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个大小为 <code>m x n</code> 的整数矩阵 <code>grid</code> 和一个大小为 <code>k</code> 的数组 <code>queries</code></p>
<p>找出一个大小为 <code>k</code> 的数组 <code>answer</code> ,且满足对于每个整数 <code>queries[i]</code> ,你从矩阵 <strong>左上角</strong> 单元格开始,重复以下过程:</p>
<ul>
<li>如果 <code>queries[i]</code> <strong>严格</strong> 大于你当前所处位置单元格,如果该单元格是第一次访问,则获得 1 分,并且你可以移动到所有 <code>4</code> 个方向(上、下、左、右)上任一 <strong>相邻</strong> 单元格。</li>
<li>否则,你不能获得任何分,并且结束这一过程。</li>
</ul>
<p>在过程结束后,<code>answer[i]</code> 是你可以获得的最大分数。注意,对于每个查询,你可以访问同一个单元格 <strong>多次</strong></p>
<p>返回结果数组 <code>answer</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/10/19/yetgriddrawio.png" style="width: 571px; height: 151px;" />
<pre>
<strong>输入:</strong>grid = [[1,2,3],[2,5,7],[3,5,1]], queries = [5,6,2]
<strong>输出:</strong>[5,8,1]
<strong>解释:</strong>上图展示了每个查询中访问并获得分数的单元格。</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/10/20/yetgriddrawio-2.png" />
<pre>
<strong>输入:</strong>grid = [[5,2,1],[1,1,2]], queries = [3]
<strong>输出:</strong>[0]
<strong>解释:</strong>无法获得分数,因为左上角单元格的值大于等于 3 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>2 &lt;= m, n &lt;= 1000</code></li>
<li><code>4 &lt;= m * n &lt;= 10<sup>5</sup></code></li>
<li><code>k == queries.length</code></li>
<li><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= grid[i][j], queries[i] &lt;= 10<sup>6</sup></code></li>
</ul>