全部评论
可以的,等我过会发
不过我也就会这一题……真的是劝退型笔试
不知道这个行不行。。最后时刻断网了 我擦 法第一题
from collections import Counter
num_input=int(input())
A0=[]
A1=[]
time=[]
for i in range(1,num_input):
for j in range(1,num_input):
if i+j<=num_input:
A0.append(i)
A1.append(j)
for len_l in range(len(A0)):
if num_input/(A0[len_l]+A1[len_l])>int(num_input/(A0[len_l]+A1[len_l])):
time.append(int(num_input/(A0[len_l]+A1[len_l]))+3)
else:
time.append(int(num_input/(A0[len_l]+A1[len_l]))+2)
counter_time=dict(Counter(time))
for i,j in counter_time.items():
print(i,j)
马上还有一场,去吃饭了代码可能来不及发了。大概思想是,如果给的数是x,假设前一个数为y,那么倒数第三个数是x-y,倒数第四个数是2y-x,然后保证每个数>0,可以得到m的区间。3个数m介于1到x之间,4个数的话m介于1/2x到x之间,5个数的话m介于1/2x到2/3x之间,注意都是开区间。会发现那个分数的分子分母是斐波拉契数列,然后更新就好了。如果m取不到了,就停止循环
# 搜狗第一题 神奇的数列
x = int(input())
dict1 = {}
for m in range(1,100):
dict1[m] = 0
for f1 in range(1, 100):
for f2 in range(1, 100):
s = 0
i = 2 #下标
a = f1
b = f2
while s <= x:
s = a + b
i += 1
if s == x:
if dict1[i] == 0:
temp = 0
dict1[i] += 1
break
a = b
b = s
for m,n in sorted(dict1.items()):
if n !=0:
print(m,n)
相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享