讨论 / 为什么有3个点过不了啊!
李梦雨 2011-11-08 16:17:00
点我顶贴 收藏 删除
bfs做的,怎么调那三个点就是不过。

求大牛指导!

const h:array[1..4]of integer=(0,0,1,-1);

e:array[1..4]of integer=(1,-1,0,0);

type team=record

l,r:longint;

end;

var a:string; ans,n,m,i,j,num:longint;

w:array[0..100000,0..60]of integer;

f:array[0..100000]of team;

p:array[0..100000,0..60]of boolean;

procedure init;

begin

fillchar(w,sizeof(w),0);

readln(n,m);

for i:=1 to n do

begin

readln(a);

for j:=1 to m do

begin

if a[j]='#' then w[i,j]:=2;

if a[j]='R' then w[i,j]:=1;

end;

end;

end;

procedure bfs(x,y:longint);

var l,r,head,tail,v:longint;

begin

head:=0;tail:=1;

f[1].l:=x;f[1].r:=y;

fillchar(p,sizeof(p),true);

p[x,y]:=false;

while head<tail do

begin

inc(head);

l:=f[head].l;r:=f[head].r;

for v:=1 to 4 do

begin

if (l+h[v]>0)and(r+e[v]>0)and(r+e[v]<=n)and(l+h[v]<=m)and(p[l+h[v],r+e[v]])and(w[l+h[v],r+e[v]]<>2) then

begin

inc(tail);

f[tail].l:=l+h[v];

f[tail].r:=r+e[v];

p[l+h[v],r+e[v]]:=false;

if (l+h[v]>0)and(r+e[v]>0)and(w[l+h[v],r+e[v]]=1) then inc(num);

end;

end;

end;

end;

begin

init;

ans:=0;

for i:=1 to n do

for j:=1 to m do

begin

num:=0;

fillchar(f,sizeof(f),0);

if w[i,j]=1 then

bfs(i,j);

if num>ans then ans:=num;

end;

writeln(ans+1);

end.

#1 wshhrm2@2011-11-08 15:14:00
回复 删除
回复 楼主李梦雨 的帖子

楼主,我也有3个过不了呀,你发现了拿错了了么

#2 wshhrm2@2011-11-08 15:32:00
回复 删除
楼主,我知道了

if (l+h[v]>0)and(r+e[v]>0)and(r+e[v]<=n)and(l+h[v]<=m)and(p[l+h[v],r+e[v]])and(w[l+h[v],r+e[v]]<>2) then

这句话写错了

应该是(r+e[v]<=m) and (l+h[v]<=n) ;

数据中只有3个n<>m 所以就wa3

#3 李梦雨@2011-11-08 16:17:00
回复 删除
回复 板凳wshhrm2 的帖子

谢谢了。

查看更多回复
提交回复