比赛 20121108 评测结果 AAAAAAWAAA
题目名称 造房子的学问 最终得分 90
用户昵称 张来风飘 运行时间 1.146 s
代码语言 Pascal 内存使用 3.29 MiB
提交时间 2012-11-08 11:35:19
显示代码纯文本
program project1;
var v:array[0..1,0..40000] of boolean;
    q:array[0..1,0..200000] of longint;
    step:array[0..1,0..200000] of longint;
    h,t:array[0..1] of longint;
    n,m,l1,l2,l3,d:longint;
procedure init;
begin
     assign(input,'wood.in');reset(input);
     assign(output,'wood.out');rewrite(output);
     read(n,m);
     if n=m then
     begin
          writeln(0);
          close(input);
          close(output);
          halt;
     end;
     read(l1,l2,l3,d);
     v[0,n]:=true;q[0,1]:=n;h[0]:=0;t[0]:=1;step[0,1]:=0;
     v[1,m]:=true;q[1,1]:=m;h[1]:=0;t[1]:=1;step[1,1]:=0;
end;
procedure expand(bin,new:longint);
var i:longint;
begin
     if (new>0)and(not v[bin,new])and(new<=32767) then
          begin
               v[bin,new]:=true;
               inc(t[bin]);
               q[bin,t[bin]]:=new;
               step[bin,t[bin]]:=step[bin,h[bin]]+1;
               for i:=1 to t[1-bin] do if q[1-bin,i]=new then
               begin
                    writeln(step[bin,t[bin]]+step[1-bin,i]);
                    close(input);
                    close(output);
                    halt;
               end;
          end;
end;
procedure tz(bin:longint);
var k:longint;
begin
     if bin=0 then
     begin
          inc(h[0]);
          k:=q[0,h[0]];
          expand(bin,k shr 1);
          expand(bin,d);
          expand(bin,k-d);
          expand(bin,k+l1);
          expand(bin,k+l2);
          expand(bin,k+l3);
     end else
     begin
          inc(h[1]);
          k:=q[1,h[1]];
          expand(bin,k shl 1);
          expand(bin,k shl 1+1);
          expand(bin,k-l1);
          expand(bin,k-l2);
          expand(bin,k-l3);
          expand(bin,k+d);
     end;
end;
procedure main;
begin
     while true do
     begin
          if (h[0]=t[0])and(h[1]=t[1]) then break;
          if (h[0]=t[0]) then tz(1) else
          if (h[1]=t[1]) then tz(0) else
          if t[0]<t[1] then tz(0) else tz(1);
     end;
     writeln('No solution.');
     close(input);
     close(output);
end;
begin
     init;
     main;
end.