1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-04 23:11:41 +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>5 个沉默寡言的哲学家围坐在圆桌前每人面前一盘意面。叉子放在哲学家之间的桌面上。5 个哲学家5 根叉子)</p>\n\n<p>所有的哲学家都只会在思考和进餐两种行为间交替。哲学家只有同时拿到左边和右边的叉子才能吃到面,而同一根叉子在同一时间只能被一个哲学家使用。每个哲学家吃完面后都需要把叉子放回桌面以供其他哲学家吃面。只要条件允许,哲学家可以拿起左边或者右边的叉子,但在没有同时拿到左右叉子时不能进食。</p>\n\n<p>假设面的数量没有限制,哲学家也能随便吃,不需要考虑吃不吃得下。</p>\n\n<p>设计一个进餐规则(并行算法)使得每个哲学家都不会挨饿;也就是说,在没有人知道别人什么时候想吃东西或思考的情况下,每个哲学家都可以在吃饭和思考之间一直交替下去。</p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/10/23/an_illustration_of_the_dining_philosophers_problem.png\" style=\"height: 415px; width: 400px;\"></p>\n\n<p><em>问题描述和图片来自维基百科&nbsp;<a href=\"https://en.wikipedia.org/wiki/Dining_philosophers_problem\" target=\"_blank\">wikipedia.org</a></em></p>\n\n<p>&nbsp;</p>\n\n<p>哲学家从&nbsp;<strong>0</strong> 到 <strong>4</strong> 按 <strong>顺时针</strong> 编号。请实现函数&nbsp;<code>void wantsToEat(philosopher, pickLeftFork, pickRightFork, eat, putLeftFork, putRightFork)</code></p>\n\n<ul>\n\t<li><code>philosopher</code>&nbsp;哲学家的编号。</li>\n\t<li><code>pickLeftFork</code>&nbsp;和&nbsp;<code>pickRightFork</code>&nbsp;表示拿起左边或右边的叉子。</li>\n\t<li><code>eat</code>&nbsp;表示吃面。</li>\n\t<li><code>putLeftFork</code>&nbsp;和&nbsp;<code>putRightFork</code>&nbsp;表示放下左边或右边的叉子。</li>\n\t<li>由于哲学家不是在吃面就是在想着啥时候吃面,所以思考这个方法没有对应的回调。</li>\n</ul>\n\n<p>给你 5 个线程,每个都代表一个哲学家,请你使用类的同一个对象来模拟这个过程。在最后一次调用结束之前,可能会为同一个哲学家多次调用该函数。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例:</strong></p>\n\n<pre><strong>输入:</strong>n = 1\n<strong>输出:</strong>[[4,2,1],[4,1,1],[0,1,1],[2,2,1],[2,1,1],[2,0,3],[2,1,2],[2,2,2],[4,0,3],[4,1,2],[0,2,1],[4,2,2],[3,2,1],[3,1,1],[0,0,3],[0,1,2],[0,2,2],[1,2,1],[1,1,1],[3,0,3],[3,1,2],[3,2,2],[1,0,3],[1,1,2],[1,2,2]]\n<strong>解释:</strong>\nn 表示每个哲学家需要进餐的次数。\n输出数组描述了叉子的控制和进餐的调用它的格式如下\noutput[i] = [a, b, c] (3个整数)\n- a 哲学家编号。\n- b 指定叉子:{1 : 左边, 2 : 右边}.\n- c 指定行为:{1 : 拿起, 2 : 放下, 3 : 吃面}。\n如 [4,2,1] 表示 4 号哲学家拿起了右边的叉子。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= n &lt;= 60</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 102,
"likes": 106,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -53,7 +53,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"13.8K\", \"totalSubmission\": \"23.3K\", \"totalAcceptedRaw\": 13800, \"totalSubmissionRaw\": 23309, \"acRate\": \"59.2%\"}",
"stats": "{\"totalAccepted\": \"14.3K\", \"totalSubmission\": \"24.1K\", \"totalAcceptedRaw\": 14264, \"totalSubmissionRaw\": 24099, \"acRate\": \"59.2%\"}",
"hints": [],
"solution": null,
"status": null,