Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水过。。附代码。

Posted by 597100700 at 2011-09-07 23:53:01 on Problem 2435
var a,b,c,d,e,m,n,u1,u2,v1,v2,l,r,xx,yy,zz,sum:longint;
    x:array[-1..100,-1..100]of char;
    q,p,uu,vv,x1,y1:array[0..1000000]of longint;
    flag:array[-1..100,-1..100]of boolean;
    ss:array[0..1000000]of char;
    qq:array[0..1000000]of longint;
begin
readln(n,m);
for a:=0 to 2*n do
 for b:=0 to 2*m do
  x[a,b]:='.';
for a:=1 to 2*n-1 do
 begin
 for b:=1 to 2*m-1 do
  begin
  read(x[a,b]);
  if x[a,b]='S' then
   begin
   u1:=a;
   u2:=b;
   end;
  if x[a,b]='E' then
   begin
   v1:=a;
   v2:=b;
   end;
  end;
 readln;
 end;
q[1]:=u1;
p[1]:=u2;
uu[1]:=0;
l:=0;r:=1;
flag[u1,u2]:=true;
while l<r do
 begin
 inc(l);
 xx:=q[l];yy:=p[l];
 if (xx=v1)and(yy=v2) then
  begin
  e:=l;
  break;
  end;
 if (x[xx-1,yy]<>'.')and(x[xx-2,yy]<>'.')and(not flag[xx-2,yy]) then
  begin
  flag[xx-2,yy]:=true;
  inc(r);
  q[r]:=xx-2;
  p[r]:=yy;
  vv[r]:=l;
  end;
 if (x[xx+1,yy]<>'.')and(x[xx+2,yy]<>'.')and(not flag[xx+2,yy]) then
  begin
  flag[xx+2,yy]:=true;
  inc(r);
  q[r]:=xx+2;
  p[r]:=yy;
  vv[r]:=l;
  end;
   if (x[xx,yy+1]<>'.')and(x[xx,yy+2]<>'.')and(not flag[xx,yy+2]) then
  begin
  flag[xx,yy+2]:=true;
  inc(r);
  q[r]:=xx;
  p[r]:=yy+2;
  vv[r]:=l;
  end;
   if (x[xx,yy-1]<>'.')and(x[xx,yy-2]<>'.')and(not flag[xx,yy-2]) then
  begin
  flag[xx,yy-2]:=true;
  inc(r);
  q[r]:=xx;
  p[r]:=yy-2;
  vv[r]:=l;
  end;
 end;
 while vv[e]>0 do
  begin
  inc(sum);
  x1[sum]:=q[e];
  y1[sum]:=p[e];
  e:=vv[e];
  end;
inc(sum);
x1[sum]:=u1;y1[sum]:=u2;
for a:=sum-1 downto 1 do
 begin
 if x1[a]-x1[a+1]=2 then
  ss[a]:='S';
 if x1[a]-x1[a+1]=-2 then
  ss[a]:='N';
 if y1[a]-y1[a+1]=2 then
  ss[a]:='E';
 if y1[a]-y1[a+1]=-2 then
  ss[a]:='W';
 end;
l:=sum-1;
while l>0 do
 begin
 r:=l;
 while ss[l]=ss[l-1] do
   dec(l);
 if r<>l then
 writeln(ss[r],' ',r-l+1)
 else
  writeln(ss[r],' ',1);
  dec(l);
 end;
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator