Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位大牛帮忙看看WA在哪里?

Posted by frankvista at 2010-08-01 20:16:22 on Problem 3253 and last updated at 2010-08-01 20:37:25
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 nmin : keytype; next : longint;
begin
	nmin := a.key[i];
	if (i+i <= a.n) and (a.key[i+i] < nmin) then begin
		nmin := a.key[i+i]; next := i+i;
		if (i+i+1 <= a.n) and (a.key[i+i+1] < nmin) then begin
			nmin := a.key[i+i+1]; next := i+i+1;
		end;
		keep(next);
	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[1] xor a.key[nt]; a.key[nt] := a.key[1] xor a.key[nt]; a.key[1] := a.key[1] xor 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); inc(ans,x); end;
	repeat
		if a.n = 2 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator