level 1
我打的随机快排用时与老快排差不了多少高手帮帮忙啊。。
2008年11月09日 03点11分
1
level 4
主程序中randomize;quicksort(1,n);过程:procedure quicksort(s,t:longint); var k,i,j,x:longint;begin k:=random(t-s+1)+s; x:=a[k]; a[k]:=a[s]; i:=s; j:=t; while i
=x) do dec(j); if i
s then quicksort(s,i-1); if i+1
2008年11月09日 12点11分
2
level 5
var
a:array[1..1000000]of longint;
n,i,m:longint;
procedure qsort(l,r: longint);
var i,j,x,y: longint;
begin
i:=l;j:=r; x:=a[random(r-l+1)+l];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if i<=j then begin
y:=a[i];a[i]:=a[j];a[j]:=y;inc(i);dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
begin
read(n,m);
for i:=1 to n do
read(a[i]);
qsort(1,n);
write(a[m]);
end.
2016年07月11日 07点07分
3