肥姆斯 肥姆斯
关注数: 1 粉丝数: 8 发帖数: 140 关注贴吧数: 1
一道关于贪食蛇的貌似简单又不简单的一道题:请大家看一下,谢谢! 【问题描述】  在“贪食蛇”游戏中,会有一些障碍设置在屏幕上面,增加游戏的难度。设计这些障碍的人往往要考虑这些障碍能否使得蛇能够到达除了这些障碍之外的所有地方,并且要让蛇安全地返回。┏━┓┃ ┃:这样是不行的。┗━┛┏━┓┃ ┃┃ ┗━┓:这样也是不行的。因为蛇进去以后就出不来了。┃   ┃  不仅要考虑这两种情况,我们还要考虑到有些贪食蛇游戏会允许玩家从画面的一端直接窜到另一端去。  设定画面的尺寸为38×22,允许上面这种情况,编一个程序,判断这个画面是否可行。【输入文件】  输入文件map.in只由38×22=836个“0”或“1”组成,每个“0”或“1”之间有一个空格。每38个数代表一行画面。“1”代表此格有障碍,“0”则代表没有。【输出文件】  输出文件map.out只有一个数字,“1”或“0”。“1”代表此画面可行,“0”则代表不可行。【样例输入1】1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0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 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0【样例输出2】0注:样例输入2内包含了 几乎 所有不可行的方案,您可以还原图像去参考一下。若有人做出程序,或有解题思路,请麻烦帖上来,谢谢!
〓〓 ̄ ̄扫雷 ̄ ̄★ uses crt;label 1;varo,ido,check:array[1..16,1..30]of boolean;board:array[1..16,1..30]of char;now:1..4;x,y,i,j:word;n:integer;win:boolean;procedure checkwin;var i,j:word;beginfor i:=1 to x dofor j:=1 to y doif check[i,j]<>ido[i,j] then exit;clrscr;textcolor(yellow);textbackground(black);gotoxy(5,10);write('You win!');readln;win:=true;exit;end;procedure fail;beginclrscr;textcolor(yellow);textbackground(black);clrscr;gotoxy(5,10);write('You fail!');readln;win:=true;exit;end;procedure openit(m,n:word);var h,z:integer;begino[m,n]:=false;gotoxy(n*2-1,m+2); write(board[m,n]); o[m,n]:=false;for h:=-1 to 1 dofor z:=-1 to 1 dobeginif (not(m+h in [1..x]))or(not(n+z in [1..y])) then continue;if (h=0)and(z=0) then continue;if ido[m+h,n+z] then continue;if not o[m+h,n+z] then continue;if board[m+h,n+z]=' ' then openit(m+h,n+z);gotoxy((n+z)*2-1,m+h+2); write(board[m+h,n+z]); o[m+h,n+z]:=false;end;end;procedure try(m,n:word);var h,z,k:integer;f:boolean;begink:=0; f:=true;if (board[m,n]in['1'..'9'])and(not o[m,n]) then beginfor h:=-1 to 1 dofor z:=-1 to 1 dobeginif(not(m+h in[1..x]))or(not(n+z in[1..y]))then continue;if ido[m+h,n+z] then inc(k);end;if ord(board[m,n])-48<=k then f:=false;end;if f then begintextcolor(yellow);for h:=-1 to 1 dofor z:=-1 to 1 dobeginif (not(m+h in[1..x]))or(not(n+z in[1..y]))or(not o[m+h,n+z]) then continue;gotoxy((n+z)*2-1,m+h+2); write('*');end;delay(250); textcolor(green);for h:=-1 to 1 dofor z:=-1 to 1 dobeginif (not(m+h in[1..x]))or(not(n+z in[1..y]))or(not o[m+h,n+z]) then continue;gotoxy((n+z)*2-1,m+h+2); write('=');end;textcolor(white);end elsefor h:=-1 to 1 dofor z:=-1 to 1 dobeginif (not(m+h in[1..x]))or(not(n+z in[1..y]))or(not o[m+h,n+z]) then continue;if board[m+h,n+z]=' ' then openit(m+h,n+z) else beginif board[m+h,n+z]='#' then fail;if board[m+h,n+z]in['1'..'9'] then begingotoxy((n+z)*2-1,m+h+2); write(board[m+h,n+z]); o[m+h,n+z]:=false; end;end;end;end;procedure p;var nn,h,z:integer;beginrandomize; fillchar(board,sizeof(board),' ');fillchar(check,sizeof(check),false);for i:=1 to n dobeginrepeath:=random(x)+1; z:=random(y)+1;until not check[h,z];board[h,z]:='#';check[h,z]:=true;end;for i:=1 to x dofor j:=1 to y dobeginif board[i,j]='#' then continue;nn:=0;for h:=-1 to 1 dofor z:=-1 to 1 dobeginif (not(i+h in [1..x]))or(not(j+z in [1..y])) then continue;if (h=0)and(z=0) then continue;if board[i+h,j+z]='#' then inc(nn);end;if nn<>0 then board[i,j]:=chr(48+nn);end;end;procedure zuobi;var i,j:word;begintextcolor(blue);for i:=1 to x dofor j:=1 to y doif board[i,j]='#' then begin gotoxy(j*2-1,i+2); write('='); end;textcolor(white);end;begin1:now:=1; textcolor(white); win:=false;textbackground(black);clrscr;gotoxy(25,8); write('> EASY');gotoxy(27,9); write('NORMAL');gotoxy(27,10); write('HARD');gotoxy(27,11); write('DIY');gotoxy(19,14); write('Press Space to continue.');
1 下一页