| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

已结贴   问题点数：100  回复次数：3

fun(1) = (0, 0, 0) = 1
fun(2) = (1, 0, 0) = 2
fun(3) = (0, 1, 0) = 3
fun(4) = (2, 0, 0) = 4
fun(5) = (0, 0, 1) = 5
fun(6) = (1, 1, 0) = 6
fun(7) = (3, 0, 0) = 8
fun(8) = (0, 2, 0) = 9
fun(9) = (1, 0, 1) = 10
fun(10) = (2, 1, 0) = 12
得分:100
i=0, j=0, k=0, a[0]=1;
2*a[0]、3*a[0]、5*a[0] 中 2*a[0] 最小，所以 a[1]=2*a[0]=2，i=1;
2*a[1]、3*a[0]、5*a[0] 中 3*a[0] 最小，所以 a[2]=3*a[0]=3, j=1;
2*a[1]、3*a[1]、5*a[0] 中 2*a[1] 最小，所以 a[3]=2*a[1]=4, i=2;
……

得分:0

```def hamming(n):
s = 1
import collections
q2 = collections.deque()
q3 = collections.deque()
q5 = collections.deque()
for x in range(n - 1):
q2.append(s * 2)
q3.append(s * 3)
q5.append(s * 5)
s = min(q2[0], q3[0], q5[0])
if q2[0] == s: q2.popleft()
if q3[0] == s: q3.popleft()
if q5[0] == s: q5.popleft()
return s```

```def hamming(n):
bases = [2, 3, 5]
expos = [0, 0, 0]
hamms = [1]
for _ in range(1, n):
next_hamms = [bases[i] * hamms[expos[i]] for i in range(3)]
next_hamm = min(next_hamms)
hamms.append(next_hamm)
for i in range(3):
expos[i] += int(next_hamms[i] == next_hamm)
return hamms[-1]```

[fly]存在即是合理[/fly]
得分:0

• 4
• 1/1页
• 1