解题思路:模拟题,了解运作过程即可
注意事项:使用lst.copy()静态改写列表,不要动态改写
参考代码:
n = int(input())
lst = list(reversed(list((map(int, input().split())))))
cnt = 0
def consider(lst_) :
global cnt
set_ = set(lst_)
lst_c = lst_.copy()
if len(set_) > 1 :
for i in range(1, n) :
lst_[i] = int((lst_c[i] + lst_c[i - 1]) / 2)
lst_[0] = int((lst_c[0] + lst_c[-1]) / 2)
for i in range(n) :
if divmod(lst_[i], 2)[1] == 1 :
lst_[i] += 1
cnt += 1
consider(lst_)
else :
print(cnt)
consider(lst)
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:584 |
C语言训练-字符串正反连接 (C语言代码)浏览:633 |
【绝对值排序】 (C++代码)浏览:684 |
Pascal三角 (C语言代码)格式错误浏览:533 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:522 |
WU-蓝桥杯算法提高VIP-交换Easy (C++代码)浏览:1119 |
C语言考试练习题_保留字母 (C语言代码)浏览:713 |
数组输出 (C语言代码)浏览:709 |
理财计划 (C语言代码)浏览:470 |
矩阵转置 (C语言代码)浏览:792 |