百度2022届秋招笔试题,我也不知道对不对
第一题:X星人
N, W = list(map(int, input().split(' ')))
lst = []
res = 0
for n in range(N):
line = list(map(int, input().split(' ')))
lst.append([line[0],line[1]])
lst.append([line[0],line[1]])
lst.sort(key=lambda x:(-x[1]/x[0],x[0]))
i = 0
while True:
W -= lst[i][0]
if W < 0: break
res += lst[i][1]
i += 1
print(res) 我只AC了27%第二题:礼物组合
a, b, x, y = list(map(int, input().split(' ')))
lst=[]
for i in range(min(b//max(x,y),a//max(x,y)),max(b//max(x,y),a//min(x,y))):
for j in range(i+1):
if j*x+(i-j)*y <= a and j*y+(i-j)*x <= b:
lst.append(i)
if not lst: print(0)
else: print(max(lst)) 没写对就结束了,最后的复盘,给的样例都ok,只是,太可惜了!