?? ac1276.pas
字號:
{$Q-,R-}
program tju1276;
const
maxv=127;
var
step:array[0..3,0..maxv]of word;
//first index: 0:1st cup empty; 1:1st cup full;
// 2:2st cup empty; 3:2st cup full;
q1,q2:array[1..maxv*4]of byte;
v1,v2,v3,f,r,s,a,b,c,d,t,ans:longint;
succeed:boolean;
procedure trans(a,b:byte);
begin
if a=0 then begin c:=0;d:=b;end
else if a=v1 then begin c:=1;d:=b;end
else if b=0 then begin c:=2;d:=a;end
else begin c:=3;d:=a;end;
end;
function check(a,b:byte):boolean;
begin
if (a=v3) or (b=v3) or (a+b=v3) then begin
ans:=s;check:=true;exit;
end;
check:=false;trans(a,b);
if s<step[c,d] then begin
step[c,d]:=s;
inc(r);q1[r]:=a;q2[r]:=b;
end;
end;
begin
repeat
fillchar(step,sizeof(step),255);
read(v1,v2,v3);ans:=0;
f:=0;r:=1;q1[r]:=0;q2[r]:=0;step[0,0]:=0;
repeat
inc(f);a:=q1[f];b:=q2[f];
trans(a,b);s:=step[c,d]+1;
if check(v1,b) then break;
if check(a,v2) then break;
if check(0,b) then break;
if check(a,0) then break;
t:=a+b;
if t>v2 then begin if check(t-v2,v2) then break;end
else if check(0,t) then break;
if t>v1 then begin if check(v1,t-v1) then break;end
else if check(t,0) then break;
until f=r;
writeln(ans);
until seekeof;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -