- 猫狗大战
- 2015-05-15 20:22:49 @
不懂为什么脑抽了。。。用了个快排的代码和……模拟!居然过了9个点。真心不懂第3个点是什么东西
program a01;
var
a:array[1..6000] of longint;
i,n,right,left,l,r:longint;
Procedure Qsort(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); dec(j);
end;
until i>j;
if l<j then Qsort(l,j);
if i<r then Qsort(i,r);
end;
begin
read(n);
for i := 1 to n do
read(a[i]);
qsort(1,n);
for i := 1 to n do
if (right>=round(n/2))or((left<round(n/2))and(l<r)) then begin
left:=left+1;
l := l+a[i];
end
else begin
right:=right+1;
r:=r+a[i];
end;
if l<r then writeln(l,' ',r)
else writeln(r,' ',l);
end.
1 条评论
-
AgCl不溶物 LV 5 @ 2015-07-21 13:31:09
斯……斯国一
- 1