zoukankan      html  css  js  c++  java
  • Oliver的救援pascal程序

    这题有点像电子老鼠闯迷宫,也是用广搜来做的

    我是用字符来输入的


    const
    dx:array[1..4]of longint=(1,-1,0,0);
    dy:array[1..4]of longint=(0,0,1,-1);


    var
    px,py,x,y,n,s,tail:longint;
    a:array[-1..2000,-1..2000]of char;
    father:array[1..2000000]of longint;
    state:array[1..1000000,1..2]of longint;


    procedure init;
    var
    i,j:longint;
    begin
        readln(n);
        for i:=1 to n do
        begin
            for j:=1 to n do
            read(a[i,j]);
            readln;
        end;
        readln(px,py,x,y);
    end;


    function check(x1,y1:longint):boolean;
    begin
        check:=true;
        if a[x1,y1]='1' then check:=false;
        if (x1>n)or(y1>n)or(y1<1)or(x1<1) then check:=false;
    end;


    procedure print(x:longint);
    begin
        if x=0 then exit;
        inc(s);
        print(father[x]);
    end;


    procedure bfs;
    var
    head,k:longint;
    begin
        head:=0;tail:=1;state[1,1]:=px;state[1,2]:=py;a[px,py]:='1';
        father[1]:=0;
        repeat
             inc(head);
             for k:=1 to 4 do
             if check(state[head,1]+dx[k],state[head,2]+dy[k]) then
             begin
                 inc(tail);
                 father[tail]:=head;
                 state[tail,1]:=state[head,1]+dx[k];
                 state[tail,2]:=state[head,2]+dy[k];
                 a[state[tail,1],state[tail,2]]:='1';
                 if (state[tail,1]=x)and(state[tail,2]=y) then
                 begin
                     print(father[tail]);
                     tail:=0;
                     writeln(s);
                     halt;
                 end;
             end;
        until head>=tail;
    end;
    begin
        init;
        bfs;
    end.


  • 相关阅读:
    js设置与获取Cookie
    js,正则应用
    Ajax支持跨域之Web API实现
    RSA加密解密在jsencrypt+c#的实现-博客园加密登录
    转:sqlserver无法创建索引,超时时间已到解决办法
    【转】asp.net 项目在 IE 11 下出现 “__doPostBack”未定义 的解决办法
    c#连接SFTP上传文件
    mac 修改mysql root密码
    Vue学习手记09-mock与axios拦截的使用
    Vue学习手记08-vue-cli的启动过程
  • 原文地址:https://www.cnblogs.com/YYC-0304/p/9500230.html
Copyright © 2011-2022 走看看