演示程序 链接:http://pan.baidu.com/s/1hrMy7Qk 密码:3hhy
:: dfs By blackkitty:: 算法描述:深搜set xx_0=0 && set yy_0=-1set xx_1=1 && set yy_1=0set xx_2=0 && set yy_2=1set xx_3=-1 && set yy_3=0set x=%current_x% && set y=%current_y%set flag=0call:dfs %x% %y% 0goto:eof:dfs:: <x> <y>if "%1_%2" EQU "%end_x%_%end_y%" (set flag=1 && goto:eof)set dic_%3=0:dfs_loop1set tmp=!dic_%3!set/a dfs=%3+1set/a nx=%1+!xx_%tmp%!set/a ny=%2+!yy_%tmp%!if !vis_%nx%_%ny%! EQU 0 ( if !%map%_%nx%_%ny%! EQU 1 ( call go %nx% %ny% call:dfs %nx% %ny% %dfs% ))if %flag% EQU 1 (goto:eof)set/a dic_%3+=1if !dic_%3! LSS 4 (goto dfs_loop1)goto:eof:: dbfs By blackkitty:: 算法描述:逆向广搜set xx_0=0&&set yy_0=-1set xx_1=1&&set yy_1=0set xx_2=0&&set yy_2=1set xx_3=-1&&set yy_3=0set l=0set r=1set x0=%end_x%set y0=%end_y%set nxt_%end_x%_%end_y%=0:rbfsset x=!x%l%!set y=!y%l%!:: 在地图上显示标记(x,y),演示搜索过程:: call:mark %x% %y% .set/a l+=1if "%x%_%y%" EQU "%start_x%_%start_y%" (goto rush)for /l %%i in (0,1,3) do ( set/a nx=x+!xx_%%i! set/a ny=y+!yy_%%i! set/a val=%map%_!nx!_!ny! if "!val!" EQU "1" ( if not defined nxt_!nx!_!ny! ( set nxt_!nx!_!ny!=!x!_!y! set x!r!=!nx! set y!r!=!ny! set/a r+=1 ) ))goto rbfs:rushset vv=!nxt_%start_x%_%start_y%!:rush_loopif "%vv%" EQU "0" (goto:eof)call go %vv:_= %set vv=!nxt_%vv%!goto rush_loop:mark:: <x> <y> 在地图上显示标记(x,y),用来演示搜索过程set/a _x=%1*2+%maze_x% && set/a _y=%2+%maze_y%cc %_x% %_y% && echo.%~3goto:eof新闻热点
疑难解答