const ww='ugly.';
var n,len,i:longint;
j,k:int64;
heap:array[0..6000] of int64;
procedure init;
begin
assign(input,ww+'in'); reset(input);
assign(output,ww+'out'); rewrite(output);
readln(n);
fillchar(heap,sizeof(heap),0);
heap[1]:=1; len:=1;
end;
procedure put(x:int64);
var son,fa:longint; t:int64;
begin
inc(len);
heap[len]:=x;
son:=len; fa:=son div 2;
while fa>0 do
begin
if heap[fa]>heap[son] then
begin
t:=heap[fa];
heap[fa]:=heap[son];
heap[son]:=t;
son:=fa;
fa:=son div 2;
end
else fa:=0;
end;
end;
function getmin():int64;
var fa,son:longint; t,min:int64;
begin
min:=heap[1];
heap[1]:=heap[len];
dec(len);
fa:=1; son:=fa*2;
while son<=len do
begin
if (heap[son]>heap[son+1]) and (son<len) then inc(son);
if heap[son]<heap[fa] then
begin
t:=heap[son];
heap[son]:=heap[fa];
heap[fa]:=t;
fa:=son; son:=fa*2;
end
else son:=len+1;
end;
getmin:=min;
end;
procedure clo;
begin
close(input);
close(output);
end;
begin
init;
i:=1; j:=0; k:=0;
while i<=n do
begin
j:=k;
k:=getmin();
if j<>k then
begin
inc(i);
put(k*2);
put(k*3);
put(k*5);
put(k*7);
end;
end;
writeln(k);
clo;
end.
二叉排序堆基础模板题
最新推荐文章于 2022-05-22 21:06:46 发布