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 |
经过修改,终于ACIn Reply To:哪位大牛帮忙看看WA在哪里? Posted by:frankvista at 2010-08-01 20:16:22 const nmax = 25000; type keytype = int64; heap = record n : longint; key : array[1..nmax+nmax] of keytype; end; var a : heap; ans,x,y : keytype; n,i : longint; procedure init; begin a.n := 0; end; procedure keep(i : longint); var next : longint; begin next := i; if (i+i <= a.n) then begin if a.key[i+i] < a.key[next] then next := i+i; if (i+i+1 <= a.n) and (a.key[i+i+1] < a.key[next]) then next := i+i+1; if next <> i then begin a.key[i] := a.key[i] xor a.key[next]; a.key[next] := a.key[i] xor a.key[next]; a.key[i] := a.key[i] xor a.key[next]; keep(next); end; end; end; function get_min : keytype; begin get_min := a.key[1]; end; procedure insert(x : keytype); var nt : longint; begin inc(a.n); nt := a.n; a.key[nt] := x; while (nt > 1) and (a.key[nt] < a.key[nt shr 1]) do begin a.key[nt] := a.key[nt] xor a.key[nt shr 1]; a.key[nt shr 1] := a.key[nt] xor a.key[nt shr 1]; a.key[nt] := a.key[nt] xor a.key[nt shr 1]; nt := nt shr 1; end; end; function delete_min : keytype; var nt : longint; begin delete_min := a.key[1]; nt := a.n; dec(a.n); a.key[1] := a.key[nt]; keep(1); end; begin assign(input,'temp.in'); reset(input); assign(output,'temp.out'); rewrite(output); readln(n); init; ans := 0; for i := 1 to n do begin readln(x); insert(x); dec(ans,x); end; repeat if a.n = 1 then begin inc(ans,get_min); break; end; x := delete_min; y := delete_min; inc(ans,x+y); insert(x+y); until false; writeln(ans); close(input); close(output); end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator