PersonalCorpus 版 (精华区)

158312 08:21:31 9 Mar 2002
Bozhang,HIT,P.R.China 1054 Pascal Accepted 0.02 sec 53K


var
    d:array[1..31] of byte;
    i,sum,k,n,from,too,temp:integer;
    p:array[0..30] of integer;
begin
    p[0]:=1; for i:=1 to 30 do p[i]:=p[i-1]*2;
    readln(n);
    for i:=1 to n do begin
        while eoln(input) do readln;
        read(d[i]);
    end;
    from:=1;too:=2;temp:=3;
    sum:=0;
    for i:=n downto 1 do begin
        if d[i]=too then begin
            sum:=sum+p[i-1];
            k:=from; from:=temp; temp:=k;
        end else if d[i]<>from then begin
            writeln(-1);halt;
        end else begin
            k:=temp; temp:=too; too:=k;
        end;
    end;
    writeln(sum);
end.
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.329毫秒