鱼C论坛

 找回密码
 立即注册
查看: 7206|回复: 23

[技术交流] 鱼C论坛Python精英挑战赛(第四季02期)

[复制链接]
发表于 2017-12-2 15:15:09 | 显示全部楼层
本帖最后由 qwc3000 于 2017-12-5 22:27 编辑

"""
解题思路
1、找最大值及位置
2、按照最大值 分段列表,将列表分为3类,一、逐渐上升的到最大值型; 二、以最大值为两端凹坑性;三、以最大值逐渐下降的
3、上升及凹型 求和
4、下降型 翻转  按照上升型求和
5、
"""
def list_max(P_list):
    temp_max_num=0  #最大值
    temp_max_i=0  #最大值最后出现的位置
    list_type=1
    temp=len(P_list)
    for i in range(temp):
        #如果 大于 那么max_num赋值,重新统计位置列表
        if P_list[i]>temp_max_num:
            temp_max_num=P_list[i]
            temp_max_i=i
        elif P_list[i]==temp_max_num:  #如果 等于  增加位置列表
            temp_max_i = i
    # 判断数列整体走向
    if temp_max_i<temp and temp_max_i>0: #混合型
        list_type=2
    elif temp_max_i==0: #下降型
        list_type=3
    elif temp_max_i==temp: #上升型
        list_type=1
    # print("最大值:",temp_max_num,"位置:",temp_max_i,"类型:",list_type)
    return temp_max_num,temp_max_i,temp,list_type#返回 最大值和位置 走向
# 分解
def list_FJ(P_list):
    L_r_tuple=list_max(P_list) # 获取相关内容
    print(L_r_tuple)
    # 对列表进行切片
    temp_list = []
    if L_r_tuple[3]==2: #混合时
        temp_list.append(P_list[:L_r_tuple[1]+1])
        temp_list.append(P_list[L_r_tuple[1]:])
    else: #单一 上升或者下降时
        temp_list=P_list
    return temp_list,L_r_tuple[3]
# 统计计算方法  适合上升 凹型
def total_result12(P_list):
    temp=0
    result_num=0
    for i in range(len(P_list)):
        if temp > P_list[i]:         #
            result_num=result_num+temp-P_list[i]
        else:
            temp=P_list[i]
    return result_num
# 统计计算方法2 适合下降型
def total_result3(P_list):
    P_list.reverse() #反向
    result=total_result12(P_list)
    return result
# P_list 分解后的列表
# P_type 元列表的类型
def total_list(P_list,P_type):
    temp=len(P_list)
    result=0
    if P_type==2:
        for i in range(temp-1):
            result=result+total_result12(P_list[i])
        result=result+total_result3(P_list[temp-1])  # 下降型 反向后
    elif P_type==1:
        result=result+total_result12(P_list[0])
    elif P_type==3:
        result = result + total_result3(P_list(temp - 1))  # 下降型 反向后
    return result
def max_rainwater(list_of_number):
    temp_tuple = list_FJ(list_of_number)
    result_of_max_rainwater = total_list(temp_tuple[0], temp_tuple[1])
    return result_of_max_rainwater
list1=[6,53,57,39,90,87,28,95,15,6,63,8,28,93,86,56,28,93,34,71,87,31,67,87,70,2,34,27,6,76]
#对列表进行分解,得到此列表类型,和分解后的列表
print(max_rainwater(list1))

点评

未按要求的格式写出程序  发表于 2017-12-5 21:11

评分

参与人数 1荣誉 +2 鱼币 +2 贡献 +2 收起 理由
jerryxjr1220 + 2 + 2 + 2 答题奖励

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-4-1 20:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表