⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac1276.pas

📁 这是在网络上搜集到的在东京大学的ACM上面解决的一些题目的源码
💻 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 + -