- 第k大
- 2013-12-07 15:34:57 @
readln全WA read 就对了
AC程序
var
a:array[1..100001]of longint;
n,k,i,j:longint;
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
read(n,k);
for i:=1 to n do read(a[i]);
sort(1,n);j:=0;
writeln(a[n-k+1]);
end.
WA程序
var
a:array[1..100001]of longint;
n,k,i,j:longint;
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
readln(n,k);
for i:=1 to n do readln(a[i]);
sort(1,n);j:=0;
writeln(a[n-k+1]);
end.
5 条评论
-
wanghongrui1 LV 8 @ 2016-08-27 09:12:08
纳尼
-
2014-01-23 20:08:56@
千万不要犯同样的错误
-
2014-01-23 20:08:35@
下次注意些
-
2014-01-23 20:08:21@
继续努力
-
2014-01-23 20:08:14@
真倒霉
- 1