pascal问题-合并果子

来源:百度知道 编辑:UC知道 时间:2024/06/22 00:08:50
查看状态 Show Status

状态题目:合并果子

题目编号:25-合并果子 查看该题

状态: Unaccepted
测评机: Xeond[6]
得分: 90分
提交日期: 2008-11-5 17:48:00
有效耗时: 3501毫秒
测试结果1: 通过本测试点|有效耗时188:ms
测试结果2: 通过本测试点|有效耗时172:ms
测试结果3: 通过本测试点|有效耗时172:ms
测试结果4: 测试结果错误.错误结果为:485694889

正确结果应为:485694875
测试结果5: 通过本测试点|有效耗时266:ms
测试结果6: 通过本测试点|有效耗时437:ms
测试结果7: 通过本测试点|有效耗时641:ms
测试结果8: 通过本测试点|有效耗时437:ms
测试结果9: 通过本测试点|有效耗时594:ms
测试结果10: 通过本测试点|有效耗时594:ms
提交代码:
var n,i,j,p:longint;
a,b:array[0..10001]of longint;
procedure swap(var a,b:longint);
var t:longint;
begin t:=a;a:=b;b:=t;end;
procedure qsort(l,r:longint);
var i,j,mid:longint;
begin
i:=l;j:=r;mid:=a[(l+r) div 2 ];
repeat
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if i<=j then begin swap(a[i],a[j]);inc(i);dec(j);end;
until i>j;
if i<r then qsort(i,r);
if l&l

利用快速排序+二分查找即可。
附程序
program t3(input,outptu);

var

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

n,i,s,j,low,mid,high,t,k:longint;

procedure qku(l,r:Integer);

var i,j,x,y:integer;

begin

i:=l;

j:=r;

x:=a[(l+r) div 2];

repeat

while a[i]<x do inc(i);

while a[j]>x do dec(j);

if 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 qku(l,j);

if i<r then qku(i,r);

end;

begin

readln(n);

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

qku(1,n);

for i:= 1 to n-2 do

begin

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

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

low:=i+2;

high:=n;

mid:=(high+low