[codevs1026] escaped Ralph

Source: Internet
Author: User

Regular wide search, all the way to ' X ' in each direction.

If you don't weigh it, it's theoretically right, but it will do a lot of useless calculations, either time out or the array goes out of bounds, and it's only 30 points.

However, the weight here does not mean that each point can only be passed once, but in a layer of search, each point can only go through once, search the next layer, the weight array to empty

The procedure is as follows:

 Programex1026;typeNode=RecordX,y,d:longint; End;varR,c,n,i,j,cen:longint;    t:string; Hash:Array[0..Wuyi,0..Wuyi] ofboolean;//weight Array Map:Array[0..Wuyi,0..Wuyi] ofChar; Dir:Array[1.. the] ofLongint; A:Array[1..1000000] ofnode;//Wide Search QueueprocedureBFS;varL,r,i:longint;beginL:=0; R:=1;  whileL<r Do  beginInc (L); ifA[l].d<>cen Then//If you go to the next layer of search, the array is emptied .beginFillchar (hash,sizeof (hash), true); CEN:=a[l].d;//number of layers plus oneEnd;  CaseDIR[A[L].D] of      1://NorthbeginI:=1;  whileMap[a[l].x-i,a[l].y]<>'X'  Do        begin          ifA[l].d=n ThenIf it's the last direction, the next point becomes ' *'beginmap[a[l].x-i,a[l].y]:='*';          Inc (I); End          Else            ifHASH[A[L].X-I,A[L].Y] Then            beginhash[a[l].x-i,a[l].y]:=false;              Inc (R); a[r].x:=a[l].x-i; A[R].Y:=a[l].y; A[R].D:=a[l].d+1;            Inc (I); End            ElseInc (I); End; End; 2://SouthbeginI:=1;  whileMap[a[l].x+i,a[l].y]<>'X'  Do        begin          ifA[l].d=n Then          beginmap[a[l].x+i,a[l].y]:='*';          Inc (I); End          Else            ifHASH[A[L].X+I,A[L].Y] Then            beginhash[a[l].x+i,a[l].y]:=false;              Inc (R); a[r].x:=a[l].x+i; A[R].Y:=a[l].y; A[R].D:=a[l].d+1;            Inc (I); End            ElseInc (I); End; End; 3://WestbeginI:=1;  whileMap[a[l].x,a[l].y-i]<>'X'  Do        begin          ifA[l].d=n Then          beginmap[a[l].x,a[l].y-i]:='*';          Inc (I); End          Else            ifHash[a[l].x,a[l].y-i] Then            beginhash[a[l].x,a[l].y-i]:=false;              Inc (R); a[r].x:=a[l].x; A[R].Y:=a[l].y-i; A[R].D:=a[l].d+1;            Inc (I); End            ElseInc (I); End; End; 4://EastbeginI:=1;  whileMap[a[l].x,a[l].y+i]<>'X'  Do        begin          ifA[l].d=n Then          beginmap[a[l].x,a[l].y+i]:='*';          Inc (I); End          Else            ifHash[a[l].x,a[l].y+i] Then            beginhash[a[l].x,a[l].y+i]:=false;              Inc (R); a[r].x:=a[l].x; A[R].Y:=a[l].y+i; A[R].D:=a[l].d+1;            Inc (I); End            ElseInc (I); End; End; End; End;End;beginCEN:=0;  READLN (R,C);  fori:=0  tor+1  Do     forj:=0  toc+1  DoMap[i,j]:='X';  fori:=1  toR Do  begin     forj:=1  toC Do    beginread (map[i,j]); ifmap[i,j]='*'  Then      begina[1].x:=i; a[1].y:=J; MAP[I,J]:='.';//The starting point becomes '. ' a[1].d:=1;//1th DirectionEnd; End;  READLN; End;  READLN (n);  fori:=1  toN Do  beginreadln (t); ift=' North'  Thendir[i]:=1; ift=' South'  Thendir[i]:=2; ift='WEST'  Thendir[i]:=3; ift='EAST'  Thendir[i]:=4; End;  BFs  fori:=1  toR Do  begin     forj:=1  toC Dowrite (map[i,j]);  Writeln; End;End.

[codevs1026] escaped Ralph

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.