PersonalCorpus 版 (精华区)

寄信人: sino (蚱蜢舟)
标  题: 1101
发信站: 哈工大紫丁香 (2002年03月25日19:36:14 星期一)
来  源: mtlab4.hit.edu.cn 

171902 11:38:24 25 Mar 2002
Bozhang,HIT,P.R.China 1101 Pascal Accepted 0.03 sec 102K

const p:array[1..4,1..2] of integer=((1,0),(0,-1),(-1,0),(0,1));
var
    exp:string;
    reg:array['A'..'Z'] of boolean;
    x,y,i,n,m,k,dir:integer;
    map:array[-100..100,-100..100] of char;
function Calc_exp(s:string):boolean;
var
    nst:array[1..200] of boolean;
    mst:array[1..200] of byte;
    tn,tm,i,k:integer;
begin
    mst[1]:=5; tn:=0; tm:=1;s:=s+')';
    for i:=1 to length(s) do begin
        k:=0;
        case s[i] of
            'A'..'Z': begin inc(tn); nst[tn]:=reg[s[i]] end;
            '0': begin inc(tn); nst[tn]:=false end;
            '1': begin inc(tn); nst[tn]:=true end;
            '(': begin k:=5; end;
            '!': begin k:=4; end;
            '&': begin k:=3; end;
            '|': begin k:=2; end;
            ')': begin k:=1; end;
        end;
        if k>0 then begin
            while k<=mst[tm] do begin
                case mst[tm] of
                    5: break;
                    4: nst[tn]:=not nst[tn];
                    3: begin nst[tn-1]:=nst[tn-1] and nst[tn]; dec(tn) end;
                    2: begin nst[tn-1]:=nst[tn-1] or nst[tn]; dec(tn) end;
                end;
                dec(tm);
            end;
            if (mst[tm]=5) and (k=1) then dec(tm) else begin
                inc(tm);
                mst[tm]:=k;
            end;
        end;
    end;
    result:=nst[1];
end;
begin
    readln(exp); readln(n,m,k);
    i:=pos('NOT',exp); while i<>0 do begin exp[i]:='!'; delete(exp,i+1,2);i:
=pos('NOT',exp) end;
    i:=pos('OR',exp); while i<>0 do begin exp[i]:='|'; delete(exp,i+1,1);i:=
pos('OR',exp) end;
    i:=pos('AND',exp); while i<>0 do begin exp[i]:='&'; delete(exp,i+1,2);i:
=pos('AND',exp) end;
    i:=pos('TRUE',exp); while i<>0 do begin exp[i]:='1'; delete(exp,i+1,3);i
:=pos('TRUE',exp) end;
    i:=pos('FALSE',exp); while i<>0 do begin exp[i]:='0'; delete(exp,i+1,4);
i:=pos('FALSE',exp) end;
    i:=pos(' ',exp); while i<>0 do begin delete(exp,i,1); i:=pos(' ',exp) en
d;
    fillchar(map,sizeof(map),32);
    fillchar(reg,sizeof(reg),0);
    for i:=1 to m do begin readln(x,y); map[x,y]:='f' end;
    for i:=1 to k do begin read(x,y);read(map[x,y]);readln(map[x,y])end;
    x:=0; y:=0; dir:=1;
    while TRUE do begin
        writeln(x,' ',y);
        x:=x+p[dir,1];
        y:=y+p[dir,2];
        if not ((x>=-n) and (x<=n) and (y>=-n) and (y<=n)) then break;
        if map[x,y]=' ' then continue;
        if map[x,y]='f' then begin
            if Calc_exp(exp) then begin
                inc(dir); if dir=5 then dir:=1;
            end else begin
                dec(dir); if dir=0 then dir:=4;
            end;
        end else begin
            reg[map[x,y]]:=not reg[map[x,y]];
        end;
    end;
end.

--
撷取生活中每一朵清新的浪花,智慧的浪花 ..汇成音乐的海洋.

※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: mtlab4.hit.edu.cn]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.911毫秒