测评机: Xeond[6]
得分: 80分
提交日期: 2010-7-25 15:35:00
有效耗时: 1392毫秒
测试结果1: 通过本测试点|有效耗时172ms
测试结果2: 通过本测试点|有效耗时157ms
测试结果3: 通过本测试点|有效耗时156ms
测试结果4: 测试结果错误.错误结果为:485696248
正确结果应为:485694875
测试结果5: 通过本测试点|有效耗时172ms
测试结果6: 测试结果错误.错误结果为:131174233
正确结果应为:131173003
测试结果7: 通过本测试点|有效耗时188ms
测试结果8: 通过本测试点|有效耗时172ms
测试结果9: 通过本测试点|有效耗时187ms
测试结果10: 通过本测试点|有效耗时188ms
提交代码: view sourceprint?01.Program ex1;
02.var n,i,total:longint;
03.
a:array[1..20000]of longint;
04.procedure heap(i,n:longint);
05.var x,j:longint;
06.begin
07.x:=a[i];
08.j:=2*i;
09.while j<=n do
10.begin
11.if (j+1<=n)and(a[j]>a[j+1]) then j:=j+1;
12.if (x>a[j]) then
13.begin
14.a[i]:=a[j];i:=j;j:=2*i;
15.end
16.else j:=n+1;
17.end;
18.a[i]:=x;
19.end;
20.procedure buildheap;
21.var i:integer;
22.begin
23.for i:=(n div 2) downto 1 do heap(i,n);
24.end;
25.procedure swap(var m1,m2:longint);
26.var temp:longint;
27.begin
28.temp:=m1;m1:=m2;m2:=temp;
29.end;
30.begin
31.readln(n);
32.for i:=1 to n do read(a[i]);
33.buildheap;
34.while n>1 do
35.begin
36.swap(a[1],a[n]);
37.dec(n);
38.heap(1,n);
39.swap(a[1],a[n]);
40.a[n]:=a[n]+a[n+1];
41.total:=total+a[n];
42.heap(1,n);
43.end;
44.writeln(total);
45.End.