求助(ACM_poj2299)
pascal吧
全部回复
仅看楼主
level 11
似乎没有任何问题,调试都是正确结果,但是提交上去是WA。。。[吐]哪位大神能告诉我是什么情况?
代码:(归并排序)
program poj2299;
var s:array[1..1000000]of longint;
n,i,j,k,total,num:longint;
mind,check:array[1..1000000]of longint;
results:array[1..1000]of longint;
procedure sort(f,l:longint);
var m,t,i,j,k:longint;
begin
if f=l then exit;
if f+1=l then
begin
if s[f]<=s[l] then exit
else begin
t:=s[f];
s[f]:=s[l];
s[l]:=t;
total:=total+1;
end;
end
else
begin
m:=(f+l) div 2;
sort(f,m);
sort(m+1,l);
i:=f; j:=m+1; k:=1;
while (i<=m)and(j<=l) do
begin
while (s[i]<=s[j])and(i<=m) do
begin
mind[k]:=s[i];
check[i]:=j-1-m;
i:=i+1;
k:=k+1;
end;
if i<=m then
begin
while (s[i]>s[j])and(j<=l) do
begin
mind[k]:=s[j];
j:=j+1;
k:=k+1;
end;
check[i]:=j-1-m;
end;
end;
if i<=m then
begin
while i<=m do
begin
mind[k]:=s[i];
check[i]:=l-m;
k:=k+1;
i:=i+1;
end;
end
else while j<=l do
begin
mind[k]:=s[j];
k:=k+1;
j:=j+1;
end;
for i:=1 to k-1 do
begin
j:=f+i-1;
s[j]:=mind[i];
end;
for i:=f to m do total:=total+check[i];
end;
end;
begin
assign(input,*poj2299.in*);
assign(output,*poj2299.out*);
reset(input);
rewrite(output);
num:=0;
readln(n);
while n<>0 do
begin
num:=num+1;
for i:=1 to n do readln(s[i]);
total:=0;
sort(1,n);
results[num]:=total;
readln(n);
end;
for i:=1 to num do
writeln(results[i]);
close(input);
close(output);
end.
2014年10月21日 03点10分 1
level 7
不要换行输出。。。
2014年10月21日 03点10分 2
1