1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-12-18 10:04:58 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>病毒扩散得很快,现在你的任务是尽可能地通过安装防火墙来隔离病毒。</p>\n\n<p>假设世界由&nbsp;<code>m x n</code>&nbsp;的二维矩阵&nbsp;<code>isInfected</code>&nbsp;组成,&nbsp;<code>isInfected[i][j] == 0</code>&nbsp;表示该区域未感染病毒,而 &nbsp;<code>isInfected[i][j] == 1</code>&nbsp;表示该区域已感染病毒。可以在任意 2 个相邻单元之间的共享边界上安装一个防火墙(并且只有一个防火墙)。</p>\n\n<p>每天晚上,病毒会从被感染区域向相邻未感染区域扩散,除非被防火墙隔离。现由于资源有限,每天你只能安装一系列防火墙来隔离其中一个被病毒感染的区域(一个区域或连续的一片区域),且该感染区域对未感染区域的威胁最大且 <strong>保证唯一&nbsp;</strong>。</p>\n\n<p>你需要努力使得最后有部分区域不被病毒感染,如果可以成功,那么返回需要使用的防火墙个数; 如果无法实现,则返回在世界被病毒全部感染时已安装的防火墙个数。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<p><img src=\"https://assets.leetcode.com/uploads/2021/06/01/virus11-grid.jpg\" style=\"height: 255px; width: 500px;\" /></p>\n\n<pre>\n<strong>输入:</strong> isInfected = [[0,1,0,0,0,0,0,1],[0,1,0,0,0,0,0,1],[0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0]]\n<strong>输出:</strong> 10\n<strong>解释:</strong>一共有两块被病毒感染的区域。\n在第一天添加 5 墙隔离病毒区域的左侧。病毒传播后的状态是:\n<img src=\"653\" />\n第二天在右侧添加 5 个墙来隔离病毒区域。此时病毒已经被完全控制住了。\n<img src=\"https://assets.leetcode.com/uploads/2021/06/01/virus13edited-grid.jpg\" style=\"height: 261px; width: 500px;\" />\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<p><img src=\"https://assets.leetcode.com/uploads/2021/06/01/virus2-grid.jpg\" style=\"height: 253px; width: 653px;\" /></p>\n\n<pre>\n<strong>输入:</strong> isInfected = [[1,1,1],[1,0,1],[1,1,1]]\n<strong>输出:</strong> 4\n<strong>解释:</strong> 虽然只保存了一个小区域,但却有四面墙。\n注意防火墙只建立在两个不同区域的共享边界上。\n</pre>\n\n<p><strong>示例&nbsp;3:</strong></p>\n\n<pre>\n<strong>输入:</strong> isInfected = [[1,1,1,0,0,0,0,0,0],[1,0,1,0,1,1,1,1,1],[1,1,1,0,0,0,0,0,0]]\n<strong>输出:</strong> 13\n<strong>解释:</strong> 在隔离右边感染区域后,隔离左边病毒区域只需要 2 个防火墙。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>m ==&nbsp;isInfected.length</code></li>\n\t<li><code>n ==&nbsp;isInfected[i].length</code></li>\n\t<li><code>1 &lt;= m, n &lt;= 50</code></li>\n\t<li><code>isInfected[i][j]</code>&nbsp;is either&nbsp;<code>0</code>&nbsp;or&nbsp;<code>1</code></li>\n\t<li>在整个描述的过程中,总有一个相邻的病毒区域,它将在下一轮 <strong>严格地感染更多未受污染的方块</strong>&nbsp;</li>\n</ul>\n\n<p>&nbsp;</p>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 43,
"likes": 45,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -161,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"1.8K\", \"totalSubmission\": \"3.5K\", \"totalAcceptedRaw\": 1753, \"totalSubmissionRaw\": 3486, \"acRate\": \"50.3%\"}",
"stats": "{\"totalAccepted\": \"1.9K\", \"totalSubmission\": \"3.8K\", \"totalAcceptedRaw\": 1928, \"totalSubmissionRaw\": 3849, \"acRate\": \"50.1%\"}",
"hints": [
"The implementation is long - we want to perfrom the following steps:\r\n\r\n* Find all viral regions (connected components), additionally for each region keeping track of the frontier (neighboring uncontaminated cells), and the perimeter of the region.\r\n\r\n* Disinfect the most viral region, adding it's perimeter to the answer.\r\n\r\n* Spread the virus in the remaining regions outward by 1 square."
],