- 佳佳的魔法照片
- 2014-08-13 18:58:01 @
var e:array[1..10] of longint;
w,d:array[1..50000] of longint;
i,m,n,j:longint;
procedure ss(x,y:longint);
var ii,jj,s,o,aa:longint;
begin
ii:=x;jj:=y;
s:=w[(x+y) shr 1];
aa:=d[(x+y) shr 1];
repeat
while (w[ii]>s) or ((w[ii]=s) and (d[ii]<aa)) do inc(ii);
while (w[jj]<s) or ((w[jj]=s) and (d[jj]>aa)) do dec(jj);
if ii<=jj then begin
o:=w[ii];w[ii]:=w[jj];w[jj]:=o;
o:=d[ii];d[ii]:=d[jj];d[jj]:=o;
inc(ii);dec(jj);
end;
until ii>jj;
if x<jj then ss(x,jj);
if ii<y then ss(ii,y);
end;
begin
readln(n,m);
for i:=1 to 10 do read(e[i]);
readln;
for i:=1 to n do read(w[i]);
for i:=1 to n do d[i]:=i;
ss(1,n);
for i:=1 to n do w[i]:=w[i]+e[(i-1) mod 10+1];
ss(1,n);
if m=0 then halt;
write(d[1]);
for i:=2 to m do write(' ',d[i]);
readln;
end.
5 条评论
-
氢氧化小2b LV 8 @ 2016-11-07 10:05:34
我的代码和你几乎一样,为啥就过不了呢???
Free Pascal Compiler version 3.0.0 [2015/11/16] for i386
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling foo.pas
Linking foo.exe
47 lines compiled, 0.0 sec, 28224 bytes code, 1268 bytes data
测试数据 #0: Accepted, time = 0 ms, mem = 1200 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 1200 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 1204 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 1200 KiB, score = 10
测试数据 #4: WrongAnswer, time = 0 ms, mem = 1200 KiB, score = 0
测试数据 #5: RuntimeError, time = 0 ms, mem = 1204 KiB, score = 0
测试数据 #6: RuntimeError, time = 15 ms, mem = 1200 KiB, score = 0
测试数据 #7: RuntimeError, time = 15 ms, mem = 1200 KiB, score = 0
测试数据 #8: RuntimeError, time = 15 ms, mem = 1200 KiB, score = 0
测试数据 #9: RuntimeError, time = 15 ms, mem = 1204 KiB, score = 0
RuntimeError, time = 60 ms, mem = 1204 KiB, score = 40program P1282; var n,k,i:longint; w,ar:array[1..50000] of longint; e:array[1..10] of longint; procedure sort(l,r: longint); var i,j,x,y,temp: longint; begin i:=l; j:=r; x:=w[(l+r) div 2]; y:=ar[(l+r) div 2]; repeat while (w[i]>x) or ((w[i]=x) and (ar[i]<y)) do inc(i); while (x>w[j]) or ((w[i]=x) and (ar[i]>y)) do dec(j); if not(i>j) then begin temp:=w[i]; w[i]:=w[j]; w[j]:=temp; temp:=ar[i]; ar[i]:=ar[j]; ar[j]:=temp; inc(i); dec(j); end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; begin readln(n,k); for i:=1 to 10 do read(e[i]); readln; for i:=1 to n do begin read(w[i]); ar[i]:=i; end; sort(1,n); for i:=1 to n do w[i]:=w[i]+e[(i-1) mod 10 +1]; sort(1,n); for i:=1 to k do write(ar[i],' '); end.
-
2015-04-22 18:07:28@
。。。
-
2015-04-20 20:20:40@
为什么我的快排必须要用2次才能按编号排好序???
能帮我看看么,data【i,1】是号次,2是W。change是我自己写的交换函数
procedure qsort(l,r:longint);
var mid,a,b,i:longint;
begin
mid:=data[(l+r) div 2,2]; a:=l; b:=r;
repeat
while (data[a,2]>mid) or ((data[a,2]=mid) and (data[a,1]<data[(l+r) div 2,1])) do inc(a);
while (data[b,2]<mid) or ((data[b,2]=mid) and (data[b,1]>data[(l+r) div 2,1])) do dec(b);
if a<=b then
begin
change(data[a,2],data[b,2]);
change(data[a,1],data[b,1]);
inc(a); dec(b);
end;
until a>b;
if a<r then qsort(a,r);
if l<b then qsort(l,b);
end; -
2015-03-16 12:09:47@
ok
-
2014-11-08 20:38:44@
掌握一种O(nlogn)的排序就ok了
- 1