bzoj 2464 BFS【水】
2016-12-16 21:11
302 查看
水过就好,就当是个好心情=。=
const
walk:array[1..4,1..2] of integer=((1,0),(-1,0),(0,1),(0,-1));
type
rec=record
x,y:longint;
end;
var
n,m,sx,sy,tx,ty :longint;
s :ansistring;
map :array[0..510,0..510] of char;
que :array[0..250010] of rec;
dis :array[0..510,0..510] of longint;
vis :array[0..510,0..510] of boolean;
i,j :longint;
procedure work;
var
i,j:longint;
xx,yy,h,tl,tt:longint;
begin
fillchar(dis,sizeof(dis),127);
dis[sx,sy]:=0;
que[1].x:=sx;
que[1].y:=sy;
h:=0;tl:=1;
//
while (h<>tl) do
begin
h:=h mod 250005+1;
vis[que[h].x,que[h].y]:=false;
//
for i:=1 to 4 do
begin
xx:=que[h].x+walk[i,1];
yy:=que[h].y+walk[i,2];
if (xx>0) and (xx<=n) and (yy>0) and (yy<=m) then
begin
if (map[xx,yy]<>map[que[h].x,que[h].y]) then tt:=1 else tt:=0;
if dis[xx,yy]>dis[que[h].x,que[h].y]+tt then
begin
dis[xx,yy]:=dis[que[h].x,que[h].y]+tt;
if not vis[xx,yy] then
begin
vis[xx,yy]:=true;
tl:=tl mod 250005+1;
que[tl].x:=xx;
que[tl].y:=yy;
end;
end;
end;
end;
end;
end;
begin
readln(n,m);
while (n<>0) and (m<>0) do
begin
fillchar(vis,sizeof(vis),false);
for i:=1 to n do
begin
readln(s);
for j:=1 to m do map[i,j]:=s[j];
end;
//
readln(sx,sy,tx,ty);
inc(sx);inc(sy);inc(tx);inc(ty);
work;
writeln(dis[tx,ty]);
readln(n,m);
end;
end.
——by Eirlys
const
walk:array[1..4,1..2] of integer=((1,0),(-1,0),(0,1),(0,-1));
type
rec=record
x,y:longint;
end;
var
n,m,sx,sy,tx,ty :longint;
s :ansistring;
map :array[0..510,0..510] of char;
que :array[0..250010] of rec;
dis :array[0..510,0..510] of longint;
vis :array[0..510,0..510] of boolean;
i,j :longint;
procedure work;
var
i,j:longint;
xx,yy,h,tl,tt:longint;
begin
fillchar(dis,sizeof(dis),127);
dis[sx,sy]:=0;
que[1].x:=sx;
que[1].y:=sy;
h:=0;tl:=1;
//
while (h<>tl) do
begin
h:=h mod 250005+1;
vis[que[h].x,que[h].y]:=false;
//
for i:=1 to 4 do
begin
xx:=que[h].x+walk[i,1];
yy:=que[h].y+walk[i,2];
if (xx>0) and (xx<=n) and (yy>0) and (yy<=m) then
begin
if (map[xx,yy]<>map[que[h].x,que[h].y]) then tt:=1 else tt:=0;
if dis[xx,yy]>dis[que[h].x,que[h].y]+tt then
begin
dis[xx,yy]:=dis[que[h].x,que[h].y]+tt;
if not vis[xx,yy] then
begin
vis[xx,yy]:=true;
tl:=tl mod 250005+1;
que[tl].x:=xx;
que[tl].y:=yy;
end;
end;
end;
end;
end;
end;
begin
readln(n,m);
while (n<>0) and (m<>0) do
begin
fillchar(vis,sizeof(vis),false);
for i:=1 to n do
begin
readln(s);
for j:=1 to m do map[i,j]:=s[j];
end;
//
readln(sx,sy,tx,ty);
inc(sx);inc(sy);inc(tx);inc(ty);
work;
writeln(dis[tx,ty]);
readln(n,m);
end;
end.
——by Eirlys
相关文章推荐
- bzoj 2464: 中山市选[2009]小明的游戏(BFS)
- BZOJ 1098: [POI2007]办公楼biu 并查集优化bfs找反图联通块
- 【BZOJ1194】[HNOI2006]潘多拉的盒子【BFS】【SCC】【拓扑排序】【DAG最长路】【自动机】
- 【bzoj1195】[HNOI2006]最短母串 AC自动机+状态压缩+BFS最短路
- BZOJ 4032 HEOI2015 最短不公共子串 后缀自动机+序列自动机+BFS
- 【bzoj4602】[Sdoi2016]齿轮 BFS
- [三合一 BFS 平衡树 线段树] BZOJ 2158 Crash 的旅行计划
- bzoj 1656: [Usaco2006 Jan] The Grove 树木(BFS)
- bzoj 1687: [Usaco2005 Open]Navigating the City 城市交通(BFS)
- bzoj 1627: [Usaco2007 Dec]穿越泥地【bfs】
- 【BZOJ1054】[HAOI2008]移动玩具 BFS
- 【BZOJ】1611: [Usaco2008 Feb]Meteor Shower流星雨(bfs)
- 【BZOJ】1671: [Usaco2005 Dec]Knights of Ni 骑士(bfs)
- [bfs 分层图 字典序 最短路] BZOJ 2644 Pku3967 Ideal Path
- BZOJ 2435 NOI2011 道路修建 BFS/DFS
- BFS【bzoj1667】: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛
- 【bzoj2464】中山市选[2009]小明的游戏
- bzoj 1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛(BFS)
- [BZOJ1054][HAOI2008]移动玩具 bfs+hash
- bzoj4395(技巧BFS)