(Simple wide search) Ice Cave--codeforces--540C

Source: Internet
Author: User

Http://codeforces.com/problemset/problem/540/C

You play a computer game. Your character stands on some level of a multilevel ice cave. In order-to-move on forward, you need-descend one level lower and the-only-to-do-is-to-fall through the ice.

the level of the cave where you are a rectangular square grid of&nbs P n  rows and  m  columns. Each cell consists the either from intact or from cracked ice. From each cell you can move to cells that is side-adjacent with yours (due to some limitations of the game engine can Do jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if your move to the cell with INTAC T ice, then the ice in this cell becomes cracked.

let's number the rows with integers from  1 to  n  from top to bottom and the columns with Integers from 1 to  m  from left-to-right . Let's denote a cell on the intersection of The  R -th row and The  C -th column As  ( R , C ).

You were staying in the cell (R1, c1) and this cell was cracked because you ' ve just fallen her E from a higher level. You need to fall-through the cell (R2, C2) since the exit to the next level is there. Can does this?

Input

The first line contains and integers, n and m (1≤ n, m ≤500) -the number of rows and columns in the cave description.

each of the Next  n   Lines describes the initial state of the that level of the cave, each line consists Of  m &N Bsp;characters "x" (cracked ice).

the next line contains both integers,  R 1 and  c  Span class= "Lower-index" >1  (1≤ R 1≤ n , 1≤ C 1≤ m )  -your initial coordinates. It is guaranteed that the description of the cave contains character ' x ' in Cell  ( R 1, C 1), that is, the ice The starting cell is initially cracked.

The next line contains integers r2 and C2 (1≤ r2≤ n, 1 ≤ c2≤ m)-the coordinates of the cell through which you need to fall. The final cell may be coincide with the starting one.

Output

If you can reach the destination, print 'YES ', otherwise print 'NO '.

Sample Test (s)input
4 6
X... Xx
... Xx.
. X.. X.
......
1 6
2 2
Output
YES
input
5 4
. X..
... X
x.x.
....
. Xx.
5 3
1 1
Output
NO
input
4 7
.. x.xx.
. Xx.. X.
X... X..
X......
2 2
1 6
Output
YES
Note

The first sample test one possible path is:

After the first visit of cells (2, 2) the ice on it cracks and if you step there for the second time, your character Falls through the ice as intended.

#include <iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>using namespacestd;#defineN 550CharG[n][n];intA[n][n], N, m;intdir[4][2] = {{-1,0},{0,-1},{0,1},{1,0}};structnode{intx, y;} Start, End;intBFS () {inti;    node p, q; Queue<node>Q;    Q.push (Start); ///a[start.x][start.y]--, because test instructions understood the error, died here.     while(Q.size ()) {p=Q.front (), Q.pop ();  for(i=0; i<4; i++) {q.x= p.x + dir[i][0]; Q.y= P.y + dir[i][1]; if(q.x==end.x && q.y==end.y && a[q.x][q.y]==1)return 1; if(q.x>=0&& q.x<n && q.y>=0&& q.y<m && a[q.x][q.y]==2) {A[Q.X][Q.Y]--;            Q.push (q); }        }    }    return 0;}intMain () {intI, J; scanf ("%d%d", &n, &m); memset (G,0,sizeof(G)); Memset (A,0,sizeof(a));  for(i=0; i<n; i++) {scanf ("%s", G[i]);  for(j=0; j<m; J + +)        {            if(G[i][j] = ='X') A[i][j]=1; if(G[i][j] = ='.') A[i][j]=2; }} scanf ("%d%d", &start.x, &start.y); scanf ("%d%d", &end.x, &end.y); Start.x--, start.y--; End.X--, end.y--; intAns =BFS (); if(ANS) printf ("yes\n"); Elseprintf ("no\n"); return 0;}

(Simple wide search) Ice Cave--codeforces--540C

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.