其他分享
首页 > 其他分享> > 蓝桥杯备战 Day 19 2022.3.19

蓝桥杯备战 Day 19 2022.3.19

作者:互联网

试题 历届真题 等差数列【第十届】【省赛】【B组】

 方法很简单,先排序找公差,然后用两个相邻数指除以公差-1就行了

n = int(input())
lst = input().split()
last = 0
for i in range(n):
    lst[i] = int(lst[i])


lst = sorted(lst)

this = 0
x = 100000 # 公差
for i in range(n-1):
    tmp = lst[i+1] - lst[i]
    x = min(x,tmp)

count = n
for i in range(n-1):
    if lst[i+1] == lst[i]:
        continue
    tmp = (lst[i+1] - lst[i])/x - 1
    count = count + int(tmp)
    
print(count)

标签:tmp,count,19,range,蓝桥,int,lst,公差,2022.3
来源: https://blog.csdn.net/Astoria_Csy/article/details/123595042