- 注册时间
- 2006-10-31
- 最后登录
- 2019-7-24
⑥精研
- 积分
- 1133
|
发表于 2006-11-2 16:47:10
|
显示全部楼层
迷宫? 看这里
用Turbo pascal编译运行:- program lx;
- uses crt;
- const
- b:array[0..3] of integer = (-79, 79, 1, -1);
- var
- a:array[0..1816] of boolean;
- i:integer;
- ch:char;
- procedure m(p:integer);
- var
- i, d : byte;
- begin
- a[p]:=true;
- repeat
- d:=0;
- if (p>158) and not a[p-158] then inc(d, 1);
- if (p<1659) and not a[p+158] then inc(d, 2);
- if (p mod 79<>77) and not a[p + 2] then inc(d, 4);
- if (p mod 79<>1) and not a[p - 2] then inc(d, 8);
- if d <> 0 then begin
- repeat
- i:=random(4);
- until boolean(d and(1 shl i));
- a[p + b[i]] := true;
- m(p + 2 * b[i]);
- end;
- until d = 0;
- end;
- begin
- randomize;
- repeat
- clrscr;
- fillchar(a, sizeof(a), false);
- m(80);
- For i:=0 to 1816 do begin
- if i mod 79 = 0 then writeln;
- if a[i] then write(#32) else write(#219);
- end;
- ch:=readkey;
- until ch=chr(27);
- end.
复制代码 |
|