记录编号 49564 评测结果 AAAAAAAAAA
题目名称 造房子的学问 最终得分 100
用户昵称 Gravatarluschegde 是否通过 通过
代码语言 Pascal 运行时间 0.020 s
提交时间 2012-11-08 14:56:28 内存使用 1.12 MiB
显示代码纯文本
var
n,m,i,a,b,c,l,tmp,head,tail,x:longint;
q:array [0..200000]of longint;
ans:array [0..40000]of longint;
f:array [0..40000]of boolean;
procedure pushin(x,tmp:longint);
begin
 if x>0 then
  if (ans[x]>tmp) and(f[x]) then
   begin
    inc(tail);
    q[tail]:=x;
	f[x]:=false;
	ans[x]:=tmp;
   end;
end;

begin
assign(input,'wood.in');
reset(input);
assign(output,'wood.out');
rewrite(output); 
readln(n,m);
readln(a);
readln(b);
readln(c);
readln(l);
for i:=0 to 38000 do ans[i]:=999999999;
fillchar(f,sizeof(f),true);
q[1]:=n;
f[n]:=false;
ans[n]:=0;
head:=1;
tail:=1;
while head<=tail do
begin
x:=q[head];
f[x]:=true;
tmp:=x+a;
pushin(tmp,ans[x]+1);
tmp:=x+b;
pushin(tmp,ans[x]+1);
tmp:=x+c;
pushin(tmp,ans[x]+1);
tmp:=x-l;
pushin(tmp,ans[x]+1);
tmp:=l;
pushin(tmp,ans[x]+1);
tmp:=x div 2;
pushin(tmp,ans[x]+1);
head:=head+1;
end;
if (ans[m]>=999999999) then writeln('No solution.')
else writeln(ans[m]);
close(input);
close(output);
end.