题目:
考察内容:
for + 时间窗口+list(append, sum, sort)+ join
代码:
"""
题目分析:最长时间段
且平均值小于等于minLost同时存在多个时间段,则输出多个,从大到小排序未找到返回 NULL
输入:
int minAveragetLost
list输出:数组下标对 beginIndex-endIndexeg:
1
0 1 2 3 42
0 0 100 2 2 99 0 23
0 0 0 20 2 3 4 100 0 0 0 0
思路:
不能排序,排序会打乱之前的顺序
sum + for"""
# min_average_lost = int(input())
# input_list = list(map(int, input().split()))
#
# temp = [0, 0]
# left = 0
# res_list = list()
# for left in range(0, len(input_list)):
# for right in range(left, len(input_list)):
# sum_temp = sum(input_list[left:right+1])/(right+1-left)
# if min_average_lost >= sum_temp:
# temp = [left, right]
# res_list.append(temp)
# else:
# break
#
#
# # print(res_list)
# # 求出最长时间段
# max_windows = 0
# res = list()
# for item in res_list:
# max_windows = max(max_windows, item[1]-item[0])
# if len(res_list) == 0:
# print("NULL")
# else:
# print(" ".join("-".join(map(str, i)) for i in res_list if i[1]-i[0] == max_windows))# 优化
min_average_lost = int(input())
input_list = list(map(int, input().split()))temp = [0, 0]
left = 0
res_list = list()
max_windows = 0
for left in range(0, len(input_list)):for right in range(left, len(input_list)):sum_temp = sum(input_list[left:right+1])/(right+1-left)if min_average_lost >= sum_temp:temp = [left, right]max_windows = max(max_windows, right+1-left)res_list.append(temp)else:# 后续的都不满足条件,左窗口向前移动break# print(res_list, max_windows)
# 这里其实不是排序
res_list.sort(key=lambda x: x[0], reverse=False)
# 求出最长时间段
if len(res_list) == 0:print("NULL")
else:print(" ".join("-".join(map(str, i)) for i in res_list if i[1]-i[0]+1 == max_windows))