freeCodeCamp/curriculum/challenges/chinese/08-coding-interview-prep/project-euler/problem-406-guessing-game.c...

56 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
id: 5900f5021000cf542c510015
challengeType: 5
title: 'Problem 406: Guessing Game'
videoUrl: ''
localeTitle: 问题406猜猜游戏
---
## Description
<section id="description">我们试图通过提问来找到从整数集{1,2...n}中选择的隐藏数字。我们问的每个数字问题我们得到三个可能的答案之一“你的猜测低于隐藏的数字”并且你需要花费一个成本或者“你的猜测高于隐藏的数字”和你承担b的费用或“是的就是这样游戏结束。给定na和b的值最优策略最小化最坏情况下的总成本。 <p>例如如果n = 5a = 2b = 3那么我们可以先问“2”作为我们的第一个问题。 </p><p>如果我们被告知2高于隐藏号码b = 3的成本那么我们确定“1”是隐藏号码总成本为3。如果我们被告知2低于隐藏号码a = 2的成本那么我们的下一个问题将是“4”。如果我们被告知4高于隐藏号码b = 3的成本那么我们确定“3”是隐藏号码总成本为2 + 3 = 5。如果我们被告知4低于隐藏号码a = 2的成本那么我们确定“5”是隐藏号码总成本为2 + 2 = 4。因此该策略实现的最坏情况成本为5.还可以证明这是可以实现的最低的最坏情况成本。所以事实上我们刚刚描述了给定na和b值的最优策略。 </p><p>设Cnab是针对给定na和b值的最优策略实现的最坏情况成本。 </p><p>以下是几个例子C5,2,3= 5 C500√2√3= 13.22073197 ... C20000,5,7= 82 C2000000√5√7 = 49.63755955 ...... </p><p>设Fk为斐波纳契数Fk = Fk-1 + Fk-2基本情况F1 = F2 =1.FindΣ1≤k≤30C1012√k√Fk并将答案四舍五入为8小数点后面的小数位数。 </p></section>
## Instructions
<section id="instructions">
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>euler406()</code>应返回36813.12757207。
testString: 'assert.strictEqual(euler406(), 36813.12757207, "<code>euler406()</code> should return 36813.12757207.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function euler406() {
// Good luck!
return true;
}
euler406();
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>