各位高手来看看,这个那里有问题,只得10 分。。。。。。

program fendui;

var

a:array [1..20000] of longint;

i,j,k,l,m,n:longint;

begin

readln(n);

for i:=1 to n do read (a[i]);

for i:=1 to n-1 do

for j:=i+1 to n do

begin

if a[i]>a[j]

then begin

k:=a[i];

a[i]:=a[j];

a[j]:=k;

end;

end;

for i:=2 to n do begin

m:=m+a[i]+a[1];

a[1]:=a[1]+a[i];

end;

write(m);

end.

4 条评论

  • @ 2013-10-05 17:44:48

    var
    heap:array[0..10000] of longint;
    n,len,a,b,ans:longint;

    procedure swap(var a,b:longint);
    var
    c:longint;
    begin
    c:=a;
    a:=b;
    b:=c;
    end;

    procedure put(x:longint);
    var
    son:longint;
    begin
    inc(len);
    heap[len]:=x;
    son:=len;
    while (son<>1) and (heap[son]<heap[son div 2]) do
    begin
    swap(heap[son],heap[son div 2]);
    son:=son div 2;
    end;
    end;

    function get:longint;
    var
    son,fa:longint;
    begin
    get:=heap[1];
    heap[1]:=heap[len];
    dec(len);
    fa:=1;
    while (fa*2<=len) or (fa*2+1<=len) do
    begin
    if (fa*2+1>len) or (heap[fa*2]<heap[fa*2+1]) then
    son:=fa*2
    else
    son:=fa*2+1;
    if heap[son]<heap[fa] then
    begin
    swap(heap[son],heap[fa]);
    fa:=son;
    end
    else
    break;
    end;
    end;

    procedure main;
    var
    i:longint;
    tmp:longint;
    begin
    len:=0;
    readln(n);
    for i:=1 to n do
    begin
    read(tmp);
    put(tmp);
    end;
    ans:=0;
    for i:=1 to n-1 do
    begin
    a:=get; b:=get;
    ans:=ans+a+b;
    put(a+b);
    end;
    writeln(ans);
    end;

    begin
    main;
    end.

  • @ 2009-07-31 11:25:27

    谢了

  • @ 2009-07-24 21:03:07

    问题大大的

    合并完了还要再排序

  • @ 2009-07-24 20:58:08

    问题很大啊

  • 1

信息

ID
1097
难度
6
分类
贪心 点击显示
标签
递交数
23915
已通过
6335
通过率
26%
被复制
41
上传者