mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-06 07:51:41 +08:00
移除零宽空格
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
"boundTopicId": 798465,
|
||||
"title": "Process Tasks Using Servers",
|
||||
"titleSlug": "process-tasks-using-servers",
|
||||
"content": "<p>You are given two <strong>0-indexed</strong> integer arrays <code>servers</code> and <code>tasks</code> of lengths <code>n</code> and <code>m</code> respectively. <code>servers[i]</code> is the <strong>weight</strong> of the <code>i<sup>th</sup></code> server, and <code>tasks[j]</code> is the <strong>time needed</strong> to process the <code>j<sup>th</sup></code> task <strong>in seconds</strong>.</p>\n\n<p>Tasks are assigned to the servers using a <strong>task queue</strong>. Initially, all servers are free, and the queue is <strong>empty</strong>.</p>\n\n<p>At second <code>j</code>, the <code>j<sup>th</sup></code> task is <strong>inserted</strong> into the queue (starting with the <code>0<sup>th</sup></code> task being inserted at second <code>0</code>). As long as there are free servers and the queue is not empty, the task in the front of the queue will be assigned to a free server with the <strong>smallest weight</strong>, and in case of a tie, it is assigned to a free server with the <strong>smallest index</strong>.</p>\n\n<p>If there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task. If multiple servers become free at the same time, then multiple tasks from the queue will be assigned <strong>in order of insertion</strong> following the weight and index priorities above.</p>\n\n<p>A server that is assigned task <code>j</code> at second <code>t</code> will be free again at second <code>t + tasks[j]</code>.</p>\n\n<p>Build an array <code>ans</code> of length <code>m</code>, where <code>ans[j]</code> is the <strong>index</strong> of the server the <code>j<sup>th</sup></code> task will be assigned to.</p>\n\n<p>Return <em>the array </em><code>ans</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> servers = [3,3,2], tasks = [1,2,3,2,1,2]\n<strong>Output:</strong> [2,2,0,2,1,2]\n<strong>Explanation: </strong>Events in chronological order go as follows:\n- At second 0, task 0 is added and processed using server 2 until second 1.\n- At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.\n- At second 2, task 2 is added and processed using server 0 until second 5.\n- At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.\n- At second 4, task 4 is added and processed using server 1 until second 5.\n- At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\n<strong>Output:</strong> [1,4,1,4,1,3,2]\n<strong>Explanation: </strong>Events in chronological order go as follows: \n- At second 0, task 0 is added and processed using server 1 until second 2.\n- At second 1, task 1 is added and processed using server 4 until second 2.\n- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4. \n- At second 3, task 3 is added and processed using server 4 until second 7.\n- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9. \n- At second 5, task 5 is added and processed using server 3 until second 7.\n- At second 6, task 6 is added and processed using server 2 until second 7.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>servers.length == n</code></li>\n\t<li><code>tasks.length == m</code></li>\n\t<li><code>1 <= n, m <= 2 * 10<sup>5</sup></code></li>\n\t<li><code>1 <= servers[i], tasks[j] <= 2 * 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>You are given two <strong>0-indexed</strong> integer arrays <code>servers</code> and <code>tasks</code> of lengths <code>n</code> and <code>m</code> respectively. <code>servers[i]</code> is the <strong>weight</strong> of the <code>i<sup>th</sup></code> server, and <code>tasks[j]</code> is the <strong>time needed</strong> to process the <code>j<sup>th</sup></code> task <strong>in seconds</strong>.</p>\n\n<p>Tasks are assigned to the servers using a <strong>task queue</strong>. Initially, all servers are free, and the queue is <strong>empty</strong>.</p>\n\n<p>At second <code>j</code>, the <code>j<sup>th</sup></code> task is <strong>inserted</strong> into the queue (starting with the <code>0<sup>th</sup></code> task being inserted at second <code>0</code>). As long as there are free servers and the queue is not empty, the task in the front of the queue will be assigned to a free server with the <strong>smallest weight</strong>, and in case of a tie, it is assigned to a free server with the <strong>smallest index</strong>.</p>\n\n<p>If there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task. If multiple servers become free at the same time, then multiple tasks from the queue will be assigned <strong>in order of insertion</strong> following the weight and index priorities above.</p>\n\n<p>A server that is assigned task <code>j</code> at second <code>t</code> will be free again at second <code>t + tasks[j]</code>.</p>\n\n<p>Build an array <code>ans</code> of length <code>m</code>, where <code>ans[j]</code> is the <strong>index</strong> of the server the <code>j<sup>th</sup></code> task will be assigned to.</p>\n\n<p>Return <em>the array </em><code>ans</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> servers = [3,3,2], tasks = [1,2,3,2,1,2]\n<strong>Output:</strong> [2,2,0,2,1,2]\n<strong>Explanation: </strong>Events in chronological order go as follows:\n- At second 0, task 0 is added and processed using server 2 until second 1.\n- At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.\n- At second 2, task 2 is added and processed using server 0 until second 5.\n- At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.\n- At second 4, task 4 is added and processed using server 1 until second 5.\n- At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\n<strong>Output:</strong> [1,4,1,4,1,3,2]\n<strong>Explanation: </strong>Events in chronological order go as follows: \n- At second 0, task 0 is added and processed using server 1 until second 2.\n- At second 1, task 1 is added and processed using server 4 until second 2.\n- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4. \n- At second 3, task 3 is added and processed using server 4 until second 7.\n- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9. \n- At second 5, task 5 is added and processed using server 3 until second 7.\n- At second 6, task 6 is added and processed using server 2 until second 7.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>servers.length == n</code></li>\n\t<li><code>tasks.length == m</code></li>\n\t<li><code>1 <= n, m <= 2 * 10<sup>5</sup></code></li>\n\t<li><code>1 <= servers[i], tasks[j] <= 2 * 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": "使用服务器处理任务",
|
||||
"translatedContent": "<p>给你两个 <strong>下标从 0 开始</strong> 的整数数组 <code>servers</code> 和 <code>tasks</code> ,长度分别为 <code>n</code> 和 <code>m</code> 。<code>servers[i]</code> 是第 <code>i<sup></sup></code> 台服务器的 <strong>权重</strong> ,而 <code>tasks[j]</code> 是处理第 <code>j<sup></sup></code> 项任务 <strong>所需要的时间</strong>(单位:秒)。</p>\n\n<p>你正在运行一个仿真系统,在处理完所有任务后,该系统将会关闭。每台服务器只能同时处理一项任务。第 <code>0</code> 项任务在第 <code>0</code> 秒可以开始处理,相应地,第 <code>j</code> 项任务在第 <code>j</code> 秒可以开始处理。处理第 <code>j</code> 项任务时,你需要为它分配一台 <strong>权重最小</strong> 的空闲服务器。如果存在多台相同权重的空闲服务器,请选择 <strong>下标最小</strong> 的服务器。如果一台空闲服务器在第 <code>t</code> 秒分配到第 <code>j</code> 项任务,那么在 <code>t + tasks[j]</code> 时它将恢复空闲状态。</p>\n\n<p>如果没有空闲服务器,则必须等待,直到出现一台空闲服务器,并 <strong>尽可能早</strong> 地处理剩余任务。 如果有多项任务等待分配,则按照 <strong>下标递增</strong> 的顺序完成分配。</p>\n\n<p>如果同一时刻存在多台空闲服务器,可以同时将多项任务分别分配给它们。</p>\n\n<p>构建长度为 <code>m</code> 的答案数组 <code>ans</code> ,其中 <code>ans[j]</code> 是第 <code>j</code> 项任务分配的服务器的下标。</p>\n\n<p>返回答案数组<em> </em><code>ans</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>servers = [3,3,2], tasks = [1,2,3,2,1,2]\n<strong>输出:</strong>[2,2,0,2,1,2]\n<strong>解释:</strong>事件按时间顺序如下:\n- 0 秒时,第 0 项任务加入到任务队列,使用第 2 台服务器处理到 1 秒。\n- 1 秒时,第 2 台服务器空闲,第 1 项任务加入到任务队列,使用第 2 台服务器处理到 3 秒。\n- 2 秒时,第 2 项任务加入到任务队列,使用第 0 台服务器处理到 5 秒。\n- 3 秒时,第 2 台服务器空闲,第 3 项任务加入到任务队列,使用第 2 台服务器处理到 5 秒。\n- 4 秒时,第 4 项任务加入到任务队列,使用第 1 台服务器处理到 5 秒。\n- 5 秒时,所有服务器都空闲,第 5 项任务加入到任务队列,使用第 2 台服务器处理到 7 秒。</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\n<strong>输出:</strong>[1,4,1,4,1,3,2]\n<strong>解释:</strong>事件按时间顺序如下:\n- 0 秒时,第 0 项任务加入到任务队列,使用第 1 台服务器处理到 2 秒。\n- 1 秒时,第 1 项任务加入到任务队列,使用第 4 台服务器处理到 2 秒。\n- 2 秒时,第 1 台和第 4 台服务器空闲,第 2 项任务加入到任务队列,使用第 1 台服务器处理到 4 秒。\n- 3 秒时,第 3 项任务加入到任务队列,使用第 4 台服务器处理到 7 秒。\n- 4 秒时,第 1 台服务器空闲,第 4 项任务加入到任务队列,使用第 1 台服务器处理到 9 秒。\n- 5 秒时,第 5 项任务加入到任务队列,使用第 3 台服务器处理到 7 秒。\n- 6 秒时,第 6 项任务加入到任务队列,使用第 2 台服务器处理到 7 秒。</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>servers.length == n</code></li>\n\t<li><code>tasks.length == m</code></li>\n\t<li><code>1 <= n, m <= 2 * 10<sup>5</sup></code></li>\n\t<li><code>1 <= servers[i], tasks[j] <= 2 * 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"translatedContent": "<p>给你两个 <strong>下标从 0 开始</strong> 的整数数组 <code>servers</code> 和 <code>tasks</code> ,长度分别为 <code>n</code> 和 <code>m</code> 。<code>servers[i]</code> 是第 <code>i<sup></sup></code> 台服务器的 <strong>权重</strong> ,而 <code>tasks[j]</code> 是处理第 <code>j<sup></sup></code> 项任务 <strong>所需要的时间</strong>(单位:秒)。</p>\n\n<p>你正在运行一个仿真系统,在处理完所有任务后,该系统将会关闭。每台服务器只能同时处理一项任务。第 <code>0</code> 项任务在第 <code>0</code> 秒可以开始处理,相应地,第 <code>j</code> 项任务在第 <code>j</code> 秒可以开始处理。处理第 <code>j</code> 项任务时,你需要为它分配一台 <strong>权重最小</strong> 的空闲服务器。如果存在多台相同权重的空闲服务器,请选择 <strong>下标最小</strong> 的服务器。如果一台空闲服务器在第 <code>t</code> 秒分配到第 <code>j</code> 项任务,那么在 <code>t + tasks[j]</code> 时它将恢复空闲状态。</p>\n\n<p>如果没有空闲服务器,则必须等待,直到出现一台空闲服务器,并 <strong>尽可能早</strong> 地处理剩余任务。 如果有多项任务等待分配,则按照 <strong>下标递增</strong> 的顺序完成分配。</p>\n\n<p>如果同一时刻存在多台空闲服务器,可以同时将多项任务分别分配给它们。</p>\n\n<p>构建长度为 <code>m</code> 的答案数组 <code>ans</code> ,其中 <code>ans[j]</code> 是第 <code>j</code> 项任务分配的服务器的下标。</p>\n\n<p>返回答案数组<em> </em><code>ans</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>servers = [3,3,2], tasks = [1,2,3,2,1,2]\n<strong>输出:</strong>[2,2,0,2,1,2]\n<strong>解释:</strong>事件按时间顺序如下:\n- 0 秒时,第 0 项任务加入到任务队列,使用第 2 台服务器处理到 1 秒。\n- 1 秒时,第 2 台服务器空闲,第 1 项任务加入到任务队列,使用第 2 台服务器处理到 3 秒。\n- 2 秒时,第 2 项任务加入到任务队列,使用第 0 台服务器处理到 5 秒。\n- 3 秒时,第 2 台服务器空闲,第 3 项任务加入到任务队列,使用第 2 台服务器处理到 5 秒。\n- 4 秒时,第 4 项任务加入到任务队列,使用第 1 台服务器处理到 5 秒。\n- 5 秒时,所有服务器都空闲,第 5 项任务加入到任务队列,使用第 2 台服务器处理到 7 秒。</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\n<strong>输出:</strong>[1,4,1,4,1,3,2]\n<strong>解释:</strong>事件按时间顺序如下:\n- 0 秒时,第 0 项任务加入到任务队列,使用第 1 台服务器处理到 2 秒。\n- 1 秒时,第 1 项任务加入到任务队列,使用第 4 台服务器处理到 2 秒。\n- 2 秒时,第 1 台和第 4 台服务器空闲,第 2 项任务加入到任务队列,使用第 1 台服务器处理到 4 秒。\n- 3 秒时,第 3 项任务加入到任务队列,使用第 4 台服务器处理到 7 秒。\n- 4 秒时,第 1 台服务器空闲,第 4 项任务加入到任务队列,使用第 1 台服务器处理到 9 秒。\n- 5 秒时,第 5 项任务加入到任务队列,使用第 3 台服务器处理到 7 秒。\n- 6 秒时,第 6 项任务加入到任务队列,使用第 2 台服务器处理到 7 秒。</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>servers.length == n</code></li>\n\t<li><code>tasks.length == m</code></li>\n\t<li><code>1 <= n, m <= 2 * 10<sup>5</sup></code></li>\n\t<li><code>1 <= servers[i], tasks[j] <= 2 * 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 87,
|
||||
|
Reference in New Issue
Block a user