Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
LeetCodeAnimation
Commits
c52a2b8b
Unverified
Commit
c52a2b8b
authored
Jul 02, 2019
by
XiangSshou
Committed by
GitHub
Jul 02, 2019
Browse files
添加877.石子游戏数学分析部分的新思路
parent
3df06e5f
Changes
1
Hide whitespace changes
Inline
Side-by-side
notes/LeetCode第877号问题:石子游戏.md
View file @
c52a2b8b
...
...
@@ -111,6 +111,14 @@ class Solution {
}
```
下面给给大家介绍一种简单的策略作为参考,使用这种策略可以保证先取石头的喜羊羊一定能够获胜。
首先分别计算出序号为奇数和序号为偶数的石头堆中的石头总数,然后进行比较,如果奇数堆石头总数更多则喜羊羊永远保证自己选取奇数石堆,反之则选择偶数。
举例来说,假设石堆为 [ 5,10000,2,3 ] ,那么奇数石堆总和为 7(从 1 开始编号),偶数石堆总数为 1003 ,则喜羊羊要保证自己永远选择偶数堆即第四堆和第二堆,就可以取胜。
但是这种选择方法得到的
**结果未必是最优解**
,例如石堆为 [ 2,1,3,5 ] 当使用动态规划确保喜羊羊和灰太狼都选择最优解的时候,喜羊羊会拿走 [ 2,5 ] 两堆棋子,而灰太狼则拿走 [ 1,3 ] 两堆。但是使用这种策略在即使不是最优解的情况下依然可以保证喜羊羊胜利,所以作为先手的喜羊羊必定有方法取得比赛的胜利。
看完之后,你的心情是怎么样的?
此题的LeetCode 的评论区里一片吐槽:
**这是什么沙雕题目!**
...
...
@@ -123,4 +131,4 @@ class Solution {

\ No newline at end of file

Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment