Python似乎无法解决这个题
查看原帖
Python似乎无法解决这个题
858160
LuShangWu楼主2024/4/20 19:52

第一个RE其他的全是WA为什么呀

# 20240416
# NUDTer2026
def quickSort(alist, temp, start, end):
    if start >= end:
        return
    base = alist[start]
    baseT = temp[start]
    low = start
    high = end
    while low < high:
        while low < high and alist[high] >= base:
            high -= 1
        alist[low] = alist[high]
        temp[low] = temp[high]
        while low < high and alist[low] < base:
            low += 1
        alist[high] = alist[low]
        temp[high] = temp[low]
    alist[low] = base
    temp[low] = baseT
    quickSort(alist, temp, 0, low - 1)
    quickSort(alist, temp, low + 1, high)


temp = input().split()
n = int(temp[0])  # 总堆数
m = int(temp[1])  # 总容量
index = 0  # 标记当前的堆数
value = []
mass = []
while (index < n):
    temp = input().split()
    mass.append(int(temp[0]))  # 该项商品总价值
    tempValue = int(temp[1])  # 该项商品总质量
    if(mass[index]!=0):
        value.append(tempValue / mass[index])  # 该项商品单价值
    else:
        value.append(0)
    index += 1
index = 0
values = 0  # 统计总收益
while m:
    if mass[index] <= m:
        values += mass[index] * value[index]
        m -= mass[index]
    else:
        values += value[index] * m
        m = 0
    index += 1
print("{:.2f}".format(values))
2024/4/20 19:52
加载中...