记录编号 66484 评测结果 AAAWAAAAAA
题目名称 [USACO Jan09] 激光电话 最终得分 90
用户昵称 Gravatarcuizhongyu 是否通过 未通过
代码语言 Pascal 运行时间 0.238 s
提交时间 2013-07-29 16:33:51 内存使用 0.32 MiB
显示代码纯文本
const
    jx:array[1..4]of integer=(0,1,0,-1);
    jy:array[1..4]of integer=(1,0,-1,0);
     
    var
    ch:char;
    i,j,n,m,x1,y1,x2,y2:longint;
    b:array[0..200,0..200]of longint;
     
    procedure go(x,y,k:longint);
    var
    i,j:longint;
    begin
    for i:=1 to 4 do
    if b[x+jx[i],y+jy[i]]>b[x,y] then
    begin
    b[x+jx[i],y+jy[i]]:=b[x,y];
    if i<>k then inc(b[x+jx[i],y+jy[i]]);
    go(x+jx[i],y+jy[i],i);
    end;
    end;
     
    begin
    assign(input,'lphone.in'); reset(input);
    assign(output,'lphone.out'); rewrite(output);
    readln(m,n);
    for i:=0 to n+1 do
    for j:=0 to m+1 do
    b[i,j]:=-3;
    for i:=1 to n do
    for j:=1 to m do
    b[i,j]:=999999;
    for i:=1 to n do
    begin
    for j:=1 to m do
    begin
    read(ch);
    case ch of
    'C':begin
    if (x1=0)and(y1=0) then
    begin
    x1:=i;
    y1:=j;
    end
    else begin
    x2:=i;
    y2:=j;
    end;
    end;
     
    '*':b[i,j]:=-3;
    end;
    end;
    readln;
    end;
    b[x1,y1]:=-1;
    go(x1,y1,0);
    writeln(b[x2,y2]);
    close(input);
    close(output);
    end.