Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这是什么问题var n,sum1,sum2,dt,ddt:longint; a,b:array[0..10000] of longint; procedure qs(l,r:longint); var i,j,k,t:longint; begin i:=l;j:=r;k:=a[(i+j) >> 1]; repeat while a[i]>k do inc(i); while a[j]<k do dec(j); if i<=j then begin t:=a[i];a[i]:=a[j];a[j]:=t; t:=b[i];b[i]:=b[j];b[j]:=t; inc(i);dec(j); end; until i>j; if i<r then qs(i,r); if j>l then qs(l,j); end; procedure init; var i:longint; begin randomize; readln(n); for i:=1 to 3*n do read(a[i]); for i:=1 to 3*n do b[i]:=i; qs(1,n*3); end; procedure work; var i,j,k,t:longint; begin for i:=1 to n do inc(sum1,a[i]); for i:=n+1 to n*2 do inc(sum2,a[i]); ddt:=(n >> 1)*1000; while true do begin i:=random(n)+1; j:=random(n)+n+1; t:=a[i];a[i]:=a[j];a[j]:=t; t:=b[i];b[i]:=b[j];b[j]:=t; dt:=a[i]-a[j]; sum2:=sum2-dt; sum1:=sum1+dt; if (sum2>ddt) and (sum1>ddt) then begin for k:=1 to n*3 do writeln(b[k]); halt; end; end; end; Begin init; work; End. 随机化的程序,wa啊。。。 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator