PersonalCorpus 版 (精华区)


//3196 2003/09/01 08:00:48.556 Wrong Answer 0:00.002 64 PASCAL 2730 - Toll 

program u2730;

var
    s:string;
    i,j,k,n,a,b,x,tot:integer;
    dl:array[1..52,1..52] of boolean;
    p:array[1..60000] of byte;
    best:array[1..52] of integer;
begin
{$IFNDEF ONLINE_JUDGE}
    assign(input,'input2730.txt'); reset(input);
    assign(output,'output2730.txt'); rewrite(output);
{$ENDIF}
    tot:=0;
    while true do begin
        readln(n);
        if n=-1 then break;
        fillchar(dl,sizeof(dl),0);
        for i:=1 to n do begin
            j:=1; while s[j]=' ' do inc(j);
            if s[j]>='a' then a:=ord(s[j])-ord('a')+27 else a:=ord(s[j])-ord('A')+1;
            inc(j); while s[j]=' ' do inc(j);
            if s[j]>='a' then b:=ord(s[j])-ord('a')+27 else b:=ord(s[j])-ord('A')+1;
            dl[a,b]:=true;
            dl[b,a]:=true;
        end;
        readln(s);
        val(s,n,k);
        j:=pos(' ',s); while s[j]=' ' do inc(j);
        if s[j]>='a' then a:=ord(s[j])-ord('a')+27 else a:=ord(s[j])-ord('A')+1;
        inc(j); while s[j]=' ' do inc(j);
        if s[j]>='a' then b:=ord(s[j])-ord('a')+27 else b:=ord(s[j])-ord('A')+1;
        for i:=1 to 52 do best[i]:=maxint;
        p[1]:=b; best[b]:=n;
        i:=1;j:=2;
        while i<j do begin
            for k:=1 to 52 do if dl[k,p[i]] then begin
                if p[i]<27 then x:=(best[p[i]]*20+18) div 19 else x:=best[p[i]]+1;
                if x<best[k] then begin
                    best[k]:=x;
                    p[j]:=k;
                    inc(j);
                end;
            end;
            inc(i);
        end;
        inc(tot);
        writeln('Case ',tot,': ',best[a]);
    end;
end.
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:8.672毫秒