首页 > 贝壳笔试9.7,第三题单纯读取输入就超时
头像
菜鸡N+1号
编辑于 2020-09-07 18:17
+ 关注

贝壳笔试9.7,第三题单纯读取输入就超时

数据挖掘机器学习方向笔试第三题,用Python读取输入直接超时,啥玩意,垃圾题目浪费时间,反馈还反馈半小时

最后附上自己的答案
import sys
def solution(price, money):
    price.sort(key=lambda x: [x[1], -x[0]])
    money.sort(key=lambda x: x[1])
    res = []
    n, m = len(price), len(money)
    i, j = 0, 0
    while i < n and j < m:
        if i == n&nbs***bsp;money[j][1] < price[i][1]:
            if i > 0:
                res.append([price[i - 1][0], price[i - 1][1], money[j][0]])
            else:
                res.append([-1, -1, money[j][0]])
            j += 1
        else:
            if i < n:
                i += 1
    res.sort(key=lambda x: x[2])
    return res
T = int(input())
for _ in range(T):
    n = int(input())
    temp = list(map(int, sys.stdin.readline().strip().split()))
    price, money = [], []
    for i in range(n):
        price.append([i + 1, temp[i]])
    q = int(input())
    for i in range(q):
        x, y, z = list(map(int, sys.stdin.readline().strip().split()))
        temp = x * y * z
        money.append([i + 1, temp])
    res = solution(price, money)
    for i in range(len(res)):
        if res[i][0] == -1:
            print(-1)
        else:
            print(res[i][0], res[i][1])
补一个单纯读取输入就超时的图片


全部评论

(8) 回帖
加载中...
话题 回帖

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐