2018-10-10 22:03:03 +00:00
|
|
|
|
---
|
|
|
|
|
id: 5900f4481000cf542c50ff5a
|
|
|
|
|
challengeType: 5
|
|
|
|
|
videoUrl: ''
|
2020-10-01 15:54:21 +00:00
|
|
|
|
title: 问题219:偏差成本编码
|
2018-10-10 22:03:03 +00:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
<section id="description">设A和B为位串(0和1的序列)。如果A等于B的最左边长度(A)位,则A被称为B的前缀。例如,00110是001101001的前缀,但不是00111或100110的前缀。 <p>大小为n的无前缀代码是n个不同位串的集合,因此没有字符串是任何其他字符串的前缀。例如,这是一个大小为6的无前缀代码: </p><p> 0000,0001,001,01,10,11 </p><p>现在假设发送'0'位需要一分钱,而传输'1'需要4便士。然后,上面显示的无前缀代码的总成本是35便士,这恰好是所讨论的偏斜定价方案可能最便宜的。简而言之,我们写Cost(6)= 35。 </p><p>什么是成本(109)? </p></section>
|
|
|
|
|
|
|
|
|
|
## Instructions
|
|
|
|
|
<section id="instructions">
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
|
|
|
|
- text: <code>euler219()</code>应返回64564225042。
|
2020-02-17 16:40:55 +00:00
|
|
|
|
testString: assert.strictEqual(euler219(), 64564225042);
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
function euler219() {
|
|
|
|
|
// Good luck!
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
euler219();
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// solution required
|
|
|
|
|
```
|
2020-08-13 15:24:35 +00:00
|
|
|
|
|
|
|
|
|
/section>
|