The Magic Wind (standard IO)

Source: Internet
Author: User

Test Instructions/description:

Dr. T has recently been studying a magical wind.
This wind has a source, called the "Tuyere". The wind in the tuyere is either clockwise or counterclockwise.
This kind of wind has energy.
This wind is able to spread, if the wind can be spread around the tuyere, the wind will be like this to produce the next level of wind:


(arrows indicate the direction of the wind, the most middle is the tuyere, the wind is clockwise, the wind in the Tuyere is counterclockwise, the situation can be imagined by the physical model or inferred from this figure.) )
The energy generated by the next level of wind is determined by the topography of the new wind, and there are two types of terrain that can pass this wind:
First, the ground, the next level of wind energy and the wind energy of the tuyere equal, this terrain with "." Said.
Second, a small number of obstacles, the next level of wind energy is half the wind energy of the tuyere, this terrain with "*" expression.
Each new wind can continue to produce the next level of wind as a new tuyere.
In addition, there is a kind of terrain can not pass the wind: a large number of obstacles, with "#" expression.
If the direction of the Tuyere is a "#" terrain, then the direction will not produce the next level of wind, other directions depending on the location of the terrain, that is, if "." or "*" terrain, the direction is still spread.
Dr. T also found the superposition rule of the Magic Wind: two-ply wind superimposed, regardless of whether their steering is the same, they only retain the energy of the larger wind, that is, the wind superimposed energy and steering is the same as the energy of the larger pre-superposition of the same wind. If the superimposed two winds have the same energy and are shifted to the same, any one of them is retained. Two of the wind energy is the same and the steering does not overlap The situation is unknown, because Dr. T has not yet encountered such a situation.
Dr. T drew a few maps, and he wanted to know the direction and energy of some wind on the map.


Read in/input:

The first line of the input file wind.in is two integers m and n, indicating that the map size is m row n columns.
The next M-line, each line being n characters, will only be a few of the following:
"S" means the tuyere, which is guaranteed to have only one "s" in the diagram.
"E" means the destination, the point that Dr. T wants to know.
“.”“ * "#" see description.
Line m+2 is an integer "0" or "1", respectively, indicating that the wind in the tuyere is clockwise or counterclockwise.
The wind energy at the Convention "s" is 16384, and the topography at "s" and "E" are flat.


Output/output:

The output file is wind.out.
If the destination will have a wind spread, then output two lines: The first act an integer, for the energy of the wind of the destination; the second behavior is an integer "0" or "1" representing the meaning of the input format. In this case, the wind energy of the destination is greater than 0.
If the destination is not rumors, the output line: "There's no wind!" (double-quoted characters, all punctuation in English).


/solution:

The topic is long, but it's easy to think of a search. In short, search on the line.


Code/code:

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

Dy:array [1..4] of integer= (0,0,1,-1);
  Type Arr=record x,y:longint;
End
  var n,m,x1,x2,y1,y2:longint;
  E:array [0..500001] of arr;
  A:array [0..201,0..201] of char;
  B,v:array [0..201,0..201] of Boolean;
F:array [0..201,0..201] of Longint;
Procedure Init;
var i,j,t:longint;
  Begin READLN (N,M);
          For I:=1 to n does begin for j:=1 to M do begin read (A[i,j]); If a[i,j]= ' S ' then begin x1:=i;
              Y1:=j;
            A[i,j]:= '. ';
          End If a[i,j]= ' E ' then begin x2:=i;
              Y2:=j;
            A[i,j]:= '. ';
          End
        If a[i,j]= ' # ' then v[i,j]:=true;
      End
    READLN;
  End For i:=0 to n+1 do begin v[i,0]:=true;
    V[i,m+1]:=true;
  End For i:=0 to m+1 do begin v[0,i]:=true;
    V[n+1,i]:=true;
  End
  READLN (t); If T=0 then B[x1,y1]:=false else B[x1,y1]:=true;
f[x1,y1]:=16384;

End
function fd (X,y:longint): boolean;
Begin Exit ((X>=1) and (X<=n) and (Y>=1) and (y<=m));

End
Procedure main (X,y:longint);
var i,l,r,tx,ty,tdx,tdy:longint; Begin L:=1;
  R:=1; E[1].x:=x;
  E[1].y:=y;
  V[x,y]:=true; While L<=r does begin tx:=e[l].x;
      TY:=E[L].Y;
          For i:=1 to 4 do begin tdx:=tx+dx[i];
          Tdy:=ty+dy[i];
          if (not FD (TDX,TDY)) or (a[tdx,tdy]= ' # ') then continue;  If a[tdx,tdy]= '. ' Then BEGIN if F[TX,TY]&GT;F[TDX,TDY] then begin f[tdx,tdy]:=f[
                  Tx][ty];
                  If not b[tx,ty] then b[tdx,tdy]:=true else b[tdx,tdy]:=false;
                      If not V[TDX,TDY] THEN BEGIN Inc (R);
                      E[R].X:=TDX;
                      E[r].y:=tdy;
                    V[tdx,tdy]:=true;
                End End; End ELSE BEGIN if a[tdx,tdy]= ' * ' THEN BEGIN if f[tx,ty] div 2&
                      GT;F[TDX,TDY] THEN begin f[tdx,tdy]:=f[tx,ty] Div 2;
                      If not b[tx,ty] then b[tdx,tdy]:=true else b[tdx,tdy]:=false;
                          If not V[TDX,TDY] THEN BEGIN Inc (R);
                          E[R].X:=TDX;
                          E[r].y:=tdy;
                        V[tdx,tdy]:=true;
                    End
                End
            End
        End
      End
      Inc (L);
    V[tx,ty]:=false;
End

End
  Begin Fillchar (F,sizeof (f), 0);
  Init
  Main (X1,Y1);
      If F[x2,y2]<>0 then BEGIN Writeln (F[x2,y2]);
    If B[x2,y2] then write (' 1 ') Else write (' 0 ');
End else write (' There ', ' ', ' s no wind! ');
 End.


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.