求助,大犇快来
查看原帖
求助,大犇快来
5521
Samsara_Karma楼主2015/10/30 22:13

[codep ]

type
  xint=record
    x,y:longint;
end;
const
  qq:array[1..4]of longint=(1,-1,0,0);
  ww:array[1..4]of longint=(0,0,1,-1);
var
  n,m,i,j,h,t:longint;
  ss:array[1..1000000]of xint;
  xx:array[1..10000]of xint;
  bo:array[1..1000,1..1000]of boolean;
  ch:array[1..1000,1..1000]of char;
  q:array[1..1000,1..1000]of longint;
procedure bfs;
var
  i,ll,rr:longint;
begin
  if h>t then exit;
  for i:=1 to 4 do
  begin
    ll:=ss[h].x+qq[i];
    rr:=ss[h].y+ww[i];
    if (ll>0) and (rr>0) and (ll<=n) and (rr<=n)
    and (bo[ll,rr]) and (ch[ss[h].x,ss[h].y]<>ch[ll,rr]) then
    begin
      inc(t);
      ss[t].x:=ll;
      ss[t].y:=rr;
      bo[ll,rr]:=false;
    end;
  end;
  inc(h);
  bfs;
end;
begin
  readln(n,m);
  for i:=1 to n do
  begin
    for j:=1 to n do
      read(ch[i,j]);
    readln;
  end;
  fillchar(bo,sizeof(bo),true);
  for i:=1 to m do
  begin
    readln(xx[i].x,xx[i].y);
    if bo[xx[i].x,xx[i].y] then
    begin
      h:=1;
      t:=1;
      ss[h].x:=xx[i].x;
      ss[h].y:=xx[i].y;
      bo[xx[i].x,xx[i].y]:=false;
      bfs;
      for j:=1 to t do
        q[ss[j].x,ss[j].y]:=t;
    end;
  end;
  for i:=1 to m do
    writeln(q[xx[i].x,xx[i].y]);
end.

[/codep] 后三个点爆了,8,9为202,10为WA,求解

2015/10/30 22:13
加载中...