mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-26 07:18:56 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个二维数组 <code>tasks</code> ,用于表示 <code>n</code> 项从 <code>0</code> 到 <code>n - 1</code> 编号的任务。其中 <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> 意味着第 <code>i<sup></sup></code> 项任务将会于 <code>enqueueTime<sub>i</sub></code> 时进入任务队列,需要 <code>processingTime<sub>i</sub></code><sub> </sub>的时长完成执行。</p>\n\n<p>现有一个单线程 CPU ,同一时间只能执行 <strong>最多一项</strong> 任务,该 CPU 将会按照下述方式运行:</p>\n\n<ul>\n\t<li>如果 CPU 空闲,且任务队列中没有需要执行的任务,则 CPU 保持空闲状态。</li>\n\t<li>如果 CPU 空闲,但任务队列中有需要执行的任务,则 CPU 将会选择 <strong>执行时间最短</strong> 的任务开始执行。如果多个任务具有同样的最短执行时间,则选择下标最小的任务开始执行。</li>\n\t<li>一旦某项任务开始执行,CPU 在 <strong>执行完整个任务</strong> 前都不会停止。</li>\n\t<li>CPU 可以在完成一项任务后,立即开始执行一项新任务。</li>\n</ul>\n\n<p>返回<em> </em>CPU<em> </em>处理任务的顺序。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>tasks = [[1,2],[2,4],[3,2],[4,1]]\n<strong>输出:</strong>[0,2,3,1]\n<strong>解释:</strong>事件按下述流程运行: \n- time = 1 ,任务 0 进入任务队列,可执行任务项 = {0}\n- 同样在 time = 1 ,空闲状态的 CPU 开始执行任务 0 ,可执行任务项 = {}\n- time = 2 ,任务 1 进入任务队列,可执行任务项 = {1}\n- time = 3 ,任务 2 进入任务队列,可执行任务项 = {1, 2}\n- 同样在 time = 3 ,CPU 完成任务 0 并开始执行队列中用时最短的任务 2 ,可执行任务项 = {1}\n- time = 4 ,任务 3 进入任务队列,可执行任务项 = {1, 3}\n- time = 5 ,CPU 完成任务 2 并开始执行队列中用时最短的任务 3 ,可执行任务项 = {1}\n- time = 6 ,CPU 完成任务 3 并开始执行任务 1 ,可执行任务项 = {}\n- time = 10 ,CPU 完成任务 1 并进入空闲状态\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\n<strong>输出:</strong>[4,3,2,0,1]\n<strong>解释:</strong>事件按下述流程运行: \n- time = 7 ,所有任务同时进入任务队列,可执行任务项 = {0,1,2,3,4}\n- 同样在 time = 7 ,空闲状态的 CPU 开始执行任务 4 ,可执行任务项 = {0,1,2,3}\n- time = 9 ,CPU 完成任务 4 并开始执行任务 3 ,可执行任务项 = {0,1,2}\n- time = 13 ,CPU 完成任务 3 并开始执行任务 2 ,可执行任务项 = {0,1}\n- time = 18 ,CPU 完成任务 2 并开始执行任务 0 ,可执行任务项 = {1}\n- time = 28 ,CPU 完成任务 0 并开始执行任务 1 ,可执行任务项 = {}\n- time = 40 ,CPU 完成任务 1 并进入空闲状态</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>tasks.length == n</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= enqueueTime<sub>i</sub>, processingTime<sub>i</sub> <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 58,
|
||||
"likes": 60,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -149,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"7.2K\", \"totalSubmission\": \"20.1K\", \"totalAcceptedRaw\": 7212, \"totalSubmissionRaw\": 20084, \"acRate\": \"35.9%\"}",
|
||||
"stats": "{\"totalAccepted\": \"7.5K\", \"totalSubmission\": \"20.8K\", \"totalAcceptedRaw\": 7519, \"totalSubmissionRaw\": 20776, \"acRate\": \"36.2%\"}",
|
||||
"hints": [
|
||||
"To simulate the problem we first need to note that if at any point in time there are no enqueued tasks we need to wait to the smallest enqueue time of a non-processed element",
|
||||
"We need a data structure like a min-heap to support choosing the task with the smallest processing time from all the enqueued tasks"
|
||||
|
||||
Reference in New Issue
Block a user