| ||||||||||
| 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 | |||||||||
WTF?为甚麽我对拍了1..1500所有n都过结果还是WA然后把自己的结果拿来打表就A了啊...
是int64的问题么?
O(n^2) WA代码
program poj1338;
var q:array[0..1517] of int64;
frt,rer,n:longint;
function binfind(n:int64):longint;
var l,r,mid:longint;
begin
l:=1; r:=rer+1; while l<>r do begin
mid:=(l+r)>>1;
if q[mid]<n then l:=mid+1 else
if q[mid]>n then r:=mid
else exit(0);
end; if (q[l]<=n)or(l>1500) then exit(0) else exit(l);
end;
procedure insert(s,v:longint);
var j:longint;
begin
for j:=rer+1 downto s+1 do q[j]:=q[j-1]; q[s]:=v;
if rer<1500 then inc(rer);
end;
procedure init;
var i:longint;
head,tail:int64;
begin
fillchar(q,sizeof(q),$3f);
q[1]:=1; frt:=0; rer:=1;
while frt<rer do begin
inc(frt); head:=q[frt];
i:=binfind(head<<1);
if i<>0 then insert(i,head<<1);
i:=binfind(head*3); if i<>0 then insert(i,head*3);
i:=binfind(head*5); if i<>0 then insert(i,head*5);
end;
end;
procedure work;
var i,j,k:longint;
begin
while not seekeof do begin
readln(n);
if n=0 then break;
writeln(q[n]);
end;
end;
begin
init;
work;
end.
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator