|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def main():
sum_yao = 0
time =0
T, M = map(int, input().split())
list_yao =[]
#输入各个草药位置
for i in range(M):
list_yao.append(list(map(int, input().split())))
if list_yao[-1][0]>T:
list_yao[-1] = [0,0]
elif list_yao[-1][0]!=0:
a=float(list_yao[-1][1]/list_yao[-1][0])
list_yao[-1].append(a)
print(list_yao[-1])
#给各个草药按照性价比排序
for i in range(M-1):
for j in range(i,M-1):
temp = []
if list_yao[j][2]<list_yao[j+1][2]:
temp = list_yao[j]
list_yao[j] = list_yao[j+1]
list_yao[j+1] = temp
elif list_yao[j][2]==list_yao[j+1][2]:
if list_yao[j][1]<list_yao[j+1][1]:
temp = list_yao[i]
list_yao[j] = list_yao[j+1]
list_yao[j+1] = temp
#找出在规定时间内找最高价值的东西
for i in range(M):
if list_yao[i][0] == 0:
break
elif time<=T:
time = time + list_yao[i][0]
sum_yao = sum_yao + list_yao[i][1]
elif time>T:
time = time - list_yao[i][0]
sum_yao = sum_yao - list_yao[i][1]
print(sun_yao)
if __name__ == '__main__':
main()
70 3
71 100
69 1
[69, 1, 0.014492753623188406]
1 2
[1, 2, 2.0]
Traceback (most recent call last):
File "D:\python\arithmetic_qq2.py", line 42, in <module>
main()
File "D:\python\arithmetic_qq2.py", line 19, in main
if list_yao[j][2]<list_yao[j+1][2]:
IndexError: list index out of range
>>>
|
|