求助这题python能做吗

P1923 【深基9.例4】求第 k 小的数

sjeozq @ 2023-10-02 10:44:19

a = input().split(' ')
b = int(a[0])
c = int(a[1])
d = input().split(' ')
e = [0] * b
for k in range(0, len(d)):
    e[k] = int(d[k])

def quiksort(low, high):
    global e
    global c
    pivot = e[low]
    while low < high:
        while low < high and e[high] >= pivot:
            high -= 1
        e[low] = e[high]
        while low < high and e[low] <= pivot:
            low += 1
        e[high] = e[low]
    e[low] = pivot
    return low

start = 0
end = b
temp = quiksort(start, end-1)
while True:
    if temp == c:
        print(e[temp])
        break
    elif temp > c:
        start = start
        end = temp-1
        temp = quiksort(start, temp)
    else:
        start = temp+1
        end = end
        temp = quiksort(start, end)

by CSPSDragon @ 2023-10-28 20:30:07

不会Python的C++路过


by SAS_Ghost @ 2023-10-31 13:01:33

我觉得大概率会超时


by amcplayer @ 2023-11-05 16:26:18

3RE 2MLE 0


|