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)/访问所有点的最小时间 [minimum-time-visiting-all-points].html
2022-03-29 12:43:11 +08:00

48 lines
1.7 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>n</code> 个点,点的位置用整数坐标表示 <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> 。请你计算访问所有这些点需要的 <strong>最小时间</strong>(以秒为单位)。</p>
<p>你需要按照下面的规则在平面上移动:</p>
<ul>
<li>每一秒内,你可以:
<ul>
<li>沿水平方向移动一个单位长度,或者</li>
<li>沿竖直方向移动一个单位长度,或者</li>
<li>跨过对角线移动 <code>sqrt(2)</code> 个单位长度(可以看作在一秒内向水平和竖直方向各移动一个单位长度)。</li>
</ul>
</li>
<li>必须按照数组中出现的顺序来访问这些点。</li>
<li>在访问某个点时,可以经过该点后面出现的点,但经过的那些点不算作有效访问。</li>
</ul>
<p> </p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/11/24/1626_example_1.png" style="height: 428px; width: 500px;" /></p>
<pre>
<strong>输入:</strong>points = [[1,1],[3,4],[-1,0]]
<strong>输出:</strong>7
<strong>解释:</strong>一条最佳的访问路径是: <strong>[1,1]</strong> -> [2,2] -> [3,3] -> <strong>[3,4] </strong>-> [2,3] -> [1,2] -> [0,1] -> <strong>[-1,0]</strong>
从 [1,1] 到 [3,4] 需要 3 秒
从 [3,4] 到 [-1,0] 需要 4 秒
一共需要 7 秒</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>points = [[3,2],[-2,2]]
<strong>输出:</strong>5
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>points.length == n</code></li>
<li><code>1 <= n <= 100</code></li>
<li><code>points[i].length == 2</code></li>
<li><code>-1000 <= points[i][0], points[i][1] <= 1000</code></li>
</ul>