贝壳笔试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])
补一个单纯读取输入就超时的图片


#笔试题目##贝壳找房#
全部评论
import sys def get_buyable(P, money):     curmax = 0     curid = -1     for i in range(len(P)):         if P[i] <= money:             if P[i] > curmax:                 curmax = P[i]                 curid = i     if curid == -1:         return -1, -1     else:         return curid, curmax n = int(sys.stdin.readline().strip()) values = [] for i in range(n):     k = int(sys.stdin.readline().strip())     line = sys.stdin.readline().strip()     P = list(map(int, line.split()))     values.append(P)     q = int(sys.stdin.readline().strip())     Q = []     for j in range(q):         line = sys.stdin.readline().strip()         x, y, z = list(map(int, line.split()))         money = x * y * z         curid, curmax = get_buyable(P, money)         if curid == -1:             print(-1)         else:             print(curid + 1, curmax) 我怀疑过价格是不是从小到大,可以二分查找,但我试了2分查找,也是超时好吧
点赞
送花
回复 分享
发布于 2020-09-07 17:26
。。。调了半天不知道错在哪
点赞
送花
回复 分享
发布于 2020-09-07 17:29
现代汽车中国前瞻数字研发中心
校招火热招聘中
官网直投
先是暴力,然后二分,然后总共1000个可能的钱数打表,然后调了个寂寞
点赞
送花
回复 分享
发布于 2020-09-07 17:32
我当时懵逼了 调了半天 调了个寂寞
点赞
送花
回复 分享
发布于 2020-09-07 17:35
老哥 可以让我看看你卖糖果的代码吗?
点赞
送花
回复 分享
发布于 2020-09-07 17:36
这个题卡了IO,C++的话把cin、cout换成scanf和printf就可以过了
点赞
送花
回复 分享
发布于 2020-09-07 18:01
老哥你这有点名不符实啊~
点赞
送花
回复 分享
发布于 2020-09-07 22:26
我做的开发笔试题。用java的BufferedReader和BufferedWriter处理输入输出都错误,蒙逼了。。
点赞
送花
回复 分享
发布于 2020-09-08 09:42

相关推荐

2 收藏 评论
分享
牛客网
牛客企业服务