BEGIN
在vijos中,我用桶排序过不了,用qsort过了。
我把数组覆盖到0,在rq上,过了,为什么?
--------
(桶排序的)
var a:array[0..35000] of integer;
n,w,h,t:longint;tot:longint;
procedure init;
var temp,i,k:longint;data:array[1..200] of longint;
begin
fillchar(data,sizeof(data),0);
readln(w);
readln(n);
for i:=1 to n do begin readln(temp);inc(data[temp]);
end;
i:=1;k:=0;
repeat
if data[i]<>0 then
for temp:=1 to data[i] do
begin inc(k);a[k]:=i;end;
inc(i);
until k=n;
end;
begin
init;
if (n=2) and (a[1]+a[2]>w) then begin writeln(’2’);halt;end;
h:=1;t:=n;tot:=0;
while h<t do begin
if a[h]+a[t]<=w then begin
inc(tot);inc(h);dec(t);
end
else begin
inc(tot);dec(t);
end;
end;
if h=t then inc(tot);
writeln(tot);
end.
--------
qsort的
var i,m,n,tot,h,t:longint;
a:array[0..30000] of longint;
procedure qsort(i,j:longint);
var h,t,k,x:longint;
begin
if i>=j then exit;
k:=random(j-i+1)+i;
x:=a[i];a[i]:=a[k];a[k]:=x;
h:=i;t:=j;x:=a[h];
while h<t do begin
while (h<t) and (a[t]>x) do dec(t);
if h<t then begin a[h]:=a[t];inc(h); end;
while (h<t) and (a[h]<x) do inc(h);
if h<t then begin a[t]:=a[h];dec(t); end;
end;
a[h]:=x;
qsort(i,h-1);
qsort(h+1,j);
end;
begin
read(m);
readln(n);
for i:=1 to n do read(a[i]);
qsort(1,n);
h:=1;t:=n;
while h<t do begin
if a[h]+a[t]<=m then begin
inc(tot);inc(h);dec(t);
end
else begin
inc(tot);dec(t);
end;
end;
if h=t then inc(tot);
writeln(tot);
end.
-------
核心代码是一样的,就是排序问题~;
------
诡异~~~~ ;
------
如果大牛能结识的话,小子就ORZ了~;
------
END.