题意:给出3*k个数,要求将其分为3个长度为k的序列,使得至少有两个序列的和大于500*k.
分析:贪心+随机化.首先排序将最小的前k个去掉,剩下的才最有可能满足题意.然后随机交换
[k+1,2k]和[2*k+1,3k]这两个区间内的数,知道满足题意,然后输出.
因为k只有60,直接暴力即可.
code:
type rectype=record n,p:longint; end; var c:array[0..181] of rectype; n,k,i,x,y:longint; procedure sort(l,r:longint); var i,j,mid:longint; begin i:=l; j:=r; mid:=c[(l+r)>>1].n; while i<=j do begin while c[i].n<mid do inc(i); while c[j].n>mid do dec(j); if i<=j then begin c[0]:=c[i]; c[i]:=c[j]; c[j]:=c[0]; inc(i); dec(j); end; end; if i<r then sort(i,r); if j>l then sort(l,j); end; procedure swap(a,b:longint); var tmp:rectype; begin tmp:=c[a]; c[a]:=c[b]; c[b]:=tmp; end; function OK:boolean; var sum1,sum2:longint; begin sum1:=0; sum2:=0; for i:=k+1 to 2*k do inc(sum1,c[i].n); for i:=k*2+1 to n do inc(sum2,c[i].n); if (sum1>k*500)and(sum2>k*500) then exit(true); exit(false); end; begin readln(k); n:=k*3; for i:=1 to n do begin readln(c[i].n); c[i].p:=i; end; sort(1,n); repeat x:=random(k)+1+k; y:=random(k)+1+k*2; swap(x,y); until OK; for i:=n downto 1 do writeln(c[i].p); end.