数据好像是n=2 a=3,4 但是答案却是3162~4148
我的程序改编快排 但效率高很多 帮忙看下哪里错了?
program d501;
var
a:array[1..1000000] of longint;
n,i,x,y:longint;
function qfind(l,r,t:longint):longint;
var
i,j,m:longint;
procedure swap(i1,j1:longint);
var
t1:longint;
begin
t1:=a[i1];a[i1]:=a[j1];a[j1]:=t1;
end;
begin
i:=l;j:=r;m:=random(r-l)+l;
swap(i,m);
while i<j do
begin
while (i<j) and (a[i]<=a[j]) do j:=j-1;
swap(i,j);
while (i<j) and (a[i]<=a[j]) do i:=i+1;
swap(i,j);
end;
if t<i then qfind:=qfind(l,i-1,t);
if t>j then qfind:=qfind(j+1,r,t);
if t=i then exit(a[i]);
end;
begin
while not eof do begin
readln(n);
for i:=1 to n do readln(a[i]);
x:=qfind(1,n,(n+1) div 2);
y:=qfind(1,n,n div 2+1);
write('A=',x);
for i:=x+1 to y do
write('、',i);
writeln; end;
end.