bzoj 1656 bfs+射线法
来源:互联网 发布:网络教育发展趋势 编辑:程序博客网 时间:2024/06/05 21:10
题意:n*m的地图,给定起点,每一步可以向八个方向前进,求环绕障碍点一周最少的步数
显然是bfs,但是并不是裸的bfs
射线法见:http://www.mamicode.com/info-detail-1138212.html
type rec=record x,y:longint;end;const walk:array[1..8,1..2] of longint=((1,0),(0,1),(-1,0),(0,-1),(1,1),(1,-1),(-1,-1),(-1,1));var n,m,sx,sy,tx,ty,ans :longint; i,j :longint; s :string; map :array[0..55,0..55] of char; dis :array[0..55,0..55] of longint; que :array[0..2510] of rec;procedure bfs;var h,tl,curx,cury,k,xx,yy:longint;begin h:=0; tl:=1; que[1].x:=sx; que[1].y:=sy; dis[sx,sy]:=0; while (h<>tl) do begin h:=h mod 2505+1; curx:=que[h].x; cury:=que[h].y; for k:=1 to 8 do begin xx:=curx+walk[k,1]; yy:=cury+walk[k,2]; if (xx>0) and (yy>0) and (xx<=n) and (yy<=m) then if map[xx,yy]='.' then begin if ((curx=tx) and (cury>ty) and (xx>tx)) then continue; if (yy>ty) and (curx>tx) and (xx=tx) then continue; dis[xx,yy]:=dis[curx,cury]+1; tl:=tl mod 2505+1; que[tl].x:=xx; que[tl].y:=yy; map[xx,yy]:='X'; end; end; end;end;begin readln(n,m); for i:=1 to n do begin readln(s); for j:=1 to m do begin map[i,j]:=s[j]; if map[i,j]='X' then begin tx:=i; ty:=j; end else if map[i,j]='*' then begin sx:=i; sy:=j; map[i,j]:='X'; end; end; end; bfs; ans:=maxlongint; for i:=ty+1 to m do begin if dis[tx,i]+dis[tx+1,i]<ans then ans:=dis[tx,i]+dis[tx+1,i]; if i<m then if dis[tx,i]+dis[tx+1,i+1]<ans then ans:=dis[tx,i]+dis[tx+1,i+1]; if i>0 then if dis[tx,i]+dis[tx+1,i-1]<ans then ans:=dis[tx,i]+dis[tx+1,i-1]; end; writeln(ans+1);end.——by Eirlys
0 0
- bzoj 1656 bfs+射线法
- 1656: [Usaco2006 Jan] The Grove 树木 BFS+射线阻隔
- The Grove bfs+射线思想
- poj 3182 The Grove 【BFS+判断点在多边形内 射线法】
- BZOJ 1294: [SCOI2009]围豆豆Bean 状压DP,SPFA,计算集合射线法
- 射线
- 射线
- 射线
- 射线
- 射线
- 射线
- bzoj 4243: 交朋友 bfs
- bzoj 3161: 孤舟蓑笠翁 bfs
- bzoj 2464 BFS【水】
- bzoj 1646 bfs
- BZOJ 4761 bfs
- bzoj 1627 bfs
- bzoj 1644 bfs
- 为什么电脑WiFi图标会有一把红色的叉叉在上面?
- java-命令
- 与计算机的第一次对话“Hello world”
- Algorithm: Array(1)
- 转行穷三年?未必!
- bzoj 1656 bfs+射线法
- 友盟QQ第三方授权登陆(精简)
- lua变动参数累加_简单
- 漫谈Android移动应用软件测试
- 【linux】linux中各文件夹的作用
- 数据库三大范式
- MFC Windows程序设计学习笔记--滚动条
- jsessionid剖析
- 重建二叉树