mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-02 22:13:28 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>你有一辆货运卡车,你需要用这一辆车把一些箱子从仓库运送到码头。这辆卡车每次运输有 <strong>箱子数目的限制</strong> 和 <strong>总重量的限制</strong> 。</p>\n\n<p>给你一个箱子数组 <code>boxes</code> 和三个整数 <code>portsCount</code>, <code>maxBoxes</code> 和 <code>maxWeight</code> ,其中 <code>boxes[i] = [ports<sub>i</sub>, weight<sub>i</sub>]</code> 。</p>\n\n<ul>\n\t<li><code>ports<sub>i</sub></code> 表示第 <code>i</code> 个箱子需要送达的码头, <code>weights<sub>i</sub></code> 是第 <code>i</code> 个箱子的重量。</li>\n\t<li><code>portsCount</code> 是码头的数目。</li>\n\t<li><code>maxBoxes</code> 和 <code>maxWeight</code> 分别是卡车每趟运输箱子数目和重量的限制。</li>\n</ul>\n\n<p>箱子需要按照 <strong>数组顺序</strong> 运输,同时每次运输需要遵循以下步骤:</p>\n\n<ul>\n\t<li>卡车从 <code>boxes</code> 队列中按顺序取出若干个箱子,但不能违反 <code>maxBoxes</code> 和 <code>maxWeight</code> 限制。</li>\n\t<li>对于在卡车上的箱子,我们需要 <strong>按顺序</strong> 处理它们,卡车会通过 <strong>一趟行程</strong> 将最前面的箱子送到目的地码头并卸货。如果卡车已经在对应的码头,那么不需要 <strong>额外行程</strong> ,箱子也会立马被卸货。</li>\n\t<li>卡车上所有箱子都被卸货后,卡车需要 <strong>一趟行程</strong> 回到仓库,从箱子队列里再取出一些箱子。</li>\n</ul>\n\n<p>卡车在将所有箱子运输并卸货后,最后必须回到仓库。</p>\n\n<p>请你返回将所有箱子送到相应码头的 <b>最少行程</b> 次数。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3\n<b>输出:</b>4\n<b>解释:</b>最优策略如下:\n- 卡车将所有箱子装上车,到达码头 1 ,然后去码头 2 ,然后再回到码头 1 ,最后回到仓库,总共需要 4 趟行程。\n所以总行程数为 4 。\n注意到第一个和第三个箱子不能同时被卸货,因为箱子需要按顺序处理(也就是第二个箱子需要先被送到码头 2 ,然后才能处理第三个箱子)。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><b>输入:</b>boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6\n<b>输出:</b>6\n<b>解释:</b>最优策略如下:\n- 卡车首先运输第一个箱子,到达码头 1 ,然后回到仓库,总共 2 趟行程。\n- 卡车运输第二、第三、第四个箱子,到达码头 3 ,然后回到仓库,总共 2 趟行程。\n- 卡车运输第五个箱子,到达码头 3 ,回到仓库,总共 2 趟行程。\n总行程数为 2 + 2 + 2 = 6 。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><b>输入:</b>boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7\n<b>输出:</b>6\n<b>解释:</b>最优策略如下:\n- 卡车运输第一和第二个箱子,到达码头 1 ,然后回到仓库,总共 2 趟行程。\n- 卡车运输第三和第四个箱子,到达码头 2 ,然后回到仓库,总共 2 趟行程。\n- 卡车运输第五和第六个箱子,到达码头 3 ,然后回到仓库,总共 2 趟行程。\n总行程数为 2 + 2 + 2 = 6 。\n</pre>\n\n<p><strong>示例 4:</strong></p>\n\n<pre><b>输入:</b>boxes = [[2,4],[2,5],[3,1],[3,2],[3,7],[3,1],[4,4],[1,3],[5,2]], portsCount = 5, maxBoxes = 5, maxWeight = 7\n<b>输出:</b>14\n<b>解释:</b>最优策略如下:\n- 卡车运输第一个箱子,到达码头 2 ,然后回到仓库,总共 2 趟行程。\n- 卡车运输第二个箱子,到达码头 2 ,然后回到仓库,总共 2 趟行程。\n- 卡车运输第三和第四个箱子,到达码头 3 ,然后回到仓库,总共 2 趟行程。\n- 卡车运输第五个箱子,到达码头 3 ,然后回到仓库,总共 2 趟行程。\n- 卡车运输第六和第七个箱子,到达码头 3 ,然后去码头 4 ,然后回到仓库,总共 3 趟行程。\n- 卡车运输第八和第九个箱子,到达码头 1 ,然后去码头 5 ,然后回到仓库,总共 3 趟行程。\n总行程数为 2 + 2 + 2 + 2 + 3 + 3 = 14 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= boxes.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= portsCount, maxBoxes, maxWeight <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= ports<sub>i</sub> <= portsCount</code></li>\n\t<li><code>1 <= weights<sub>i</sub> <= maxWeight</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 29,
|
||||
"likes": 32,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -167,7 +167,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"1.2K\", \"totalSubmission\": \"2.9K\", \"totalAcceptedRaw\": 1196, \"totalSubmissionRaw\": 2909, \"acRate\": \"41.1%\"}",
|
||||
"stats": "{\"totalAccepted\": \"1.3K\", \"totalSubmission\": \"3.1K\", \"totalAcceptedRaw\": 1318, \"totalSubmissionRaw\": 3091, \"acRate\": \"42.6%\"}",
|
||||
"hints": [
|
||||
"Try to think of the most basic dp which is n^2 now optimize it",
|
||||
"Think of any range query data structure to optimize"
|
||||
|
Reference in New Issue
Block a user