Description

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

The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make 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 you move to the cell with intact ice, then the ice on 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 are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this?

Input

The first line contains two 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 level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice).

The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked.

The next line contains two 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 coincide with the starting one.

Output

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

Sample Input

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
 #include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
using namespace std; int dir[][]={,,-,,,,,-};
char mp[][];
int n,m;
int ex,ey; class point
{
public :
int x,y;
}; int ok(int x,int y)
{
return x>=&&y>=&&x<=n&&y<=m;
} int bfs(int x,int y)
{
queue<point> q; point sta,nw,nxt,ep;
ep.x=ex;
ep.y=ey;
sta.x=x,sta.y=y;
q.push(sta); while(!q.empty())
{
nw=q.front();
q.pop(); for(int i=;i<;i++)
{
nxt.x=nw.x+dir[i][];
nxt.y=nw.y+dir[i][]; if(ok(nxt.x,nxt.y))
{
if(nxt.x==ep.x&&nxt.y==ep.y)
{
if(mp[nxt.x][nxt.y]=='.')mp[nxt.x][nxt.y]='X';
else return ;
q.push(nxt);
}
else if(mp[nxt.x][nxt.y]=='.')
{
mp[nxt.x][nxt.y]='X';
q.push(nxt);
}
}
} }
return ;
}
int main()
{
int sx,sy;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++)scanf("%s",mp[i]+);
scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
if(bfs(sx,sy))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}

ice cave的更多相关文章

  1. DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

    题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...

  2. (简单广搜) Ice Cave -- codeforces -- 540C

    http://codeforces.com/problemset/problem/540/C You play a computer game. Your character stands on so ...

  3. CodeForces 540C Ice Cave (BFS)

    http://codeforces.com/problemset/problem/540/C       Ice Cave Time Limit:2000MS     Memory Limit:262 ...

  4. Codeforces Round #301 (Div. 2) C. Ice Cave BFS

    C. Ice Cave Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/problem/C ...

  5. CF#301 C:Ice Cave(简单BFS)

    C:Ice Cave 有一个m*n的地图,里面包含'.'表示完整的冰块,'X'表示有裂痕的冰块,当游戏者到达完整的冰块时,这个位置的冰块会变成有裂痕的冰块,如果到达有裂痕的冰块时,游戏者会进入下一关 ...

  6. CodeForces - 540C Ice Cave —— BFS

    题目链接:https://vjudge.net/contest/226823#problem/C You play a computer game. Your character stands on ...

  7. ICE CAVE(BFS搜索(模拟))

    Description You play a computer game. Your character stands on some level of a multilevel ice cave. ...

  8. 540C: Ice Cave

    题目链接 题意: n*m的地图,'X'表示有裂痕的冰块,'.'表示完整的冰块,有裂痕的冰块再被踩一次就会碎掉,完整的冰块被踩一次会变成有裂痕的冰块, 现在告诉起点和终点,问从起点能否走到终点并且使终点 ...

  9. CodeForces 540C Ice Cave (BFS)

    题意:给定 n * m的矩阵,让你并给定初始坐标和末坐标,你只能走'.',并且走过的'.'都会变成'X',然后问你能不能在末坐标是'X'的时候走进去. 析:这个题,在比赛时就是没做出来,其实是一个水题 ...

随机推荐

  1. javascript面向对象——tabs实例

    面向过程—>面向对象 之前在未学习面向对象时,我们都是面向过程编程的.它的优点就是简单,明了,下面就来把面向过程的tabs切换改写成面向对象的方式. html: <div class=&q ...

  2. Android的ProgressBar

    注意点: 必须在setContentView 前面设置,否则会报错. 重要的方法: progress.incrementProgressBy(int diff);//参数为进度数,进度满了为100.不 ...

  3. Cesium 获取当前视图范围

    Cesium作为一个开源的WebGlobe解决方案已经很牛了,不过因为开发的资料不多,很多功能不知道怎么实现.下面记录下自己获取Cesium当前场景范围的方法(2维中对应的是extent). exte ...

  4. Clojure学习02:语法

    相比我们传统的 c ,java ,python ,javascript等,Clojure的语法比较特别,初一看,还可能会有些不适应. 本文来介绍下Clojure的语法特点. 一.表达式 所有的Cloj ...

  5. shell脚本中每次读取文件的一行

    写法一: #!/bin/bash while read linedo      echo $line     #这里可根据实际用途变化 done < file          #需要读取的文件 ...

  6. 鹅厂揭秘——高端大气的App电量測试

    怎样评价我们开发出来的应用是耗电还是不耗电,怎样測试?这就是我们今天讨论的主题--电量測试,一个在移动应用中新出现的測试类型. 作者简单介绍 watermark/2/text/aHR0cDovL2Js ...

  7. AFNetworking2.5使用2

    链接地址:http://blog.csdn.net/abc4715760/article/details/46521111 官网下载2.5版本:http://afnetworking.com/ 此文章 ...

  8. awk内置变量 awk有许多内置变量用来设置环境信息,这些变量可以被改变,下面给出了最常用的一些变量。

    ARGC 命令行参数个数 ARGV 命令行参数排列 ENVIRON 支持队列中系统环境变量的使用 FILENAME awk浏览的文件名 FNR 浏览文件的记录数 FS 设置输入域分隔符,等价于命令行 ...

  9. extern、static、auto、register 定义变量的不同用法

    首先得说明什么叫“编译单元”.每个 .c 文件会被编译为一个 .o 文件,这个就是一个编译单元.最后所有的编译单元被链接起来,就是一个库或一个程序. 一个变量/函数,只要是在全局声明的,链接之后都隐含 ...

  10. opencv开源库

    opencv是开源库 在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib 为什么要CMake,这里我陈述自己的想法,作为一个刚使用opencv库的小白来说,有以下大概 ...