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. ARM流水线(pipeline)

  2. OpenSSL命令---rand

    用途: 用来产生伪随机字节.随机数字产生器需要一个seed,先已经说过了,在没有/dev/srandom系统下的解决方法是自己做一个~/.rnd文件.如果该程序能让随机数字产生器很满意的被seeded ...

  3. 【 D3.js 入门系列 — 2 】 绑定数据和选择元素

    1. 如何绑定数据 D3 有一个很独特的功能:能将数据绑定到 DOM 上,也就是绑定到文档上.这么说可能不好理解,例如网页中有段落元素<p>,我们可以将整数 5 与 <p>绑定 ...

  4. django perm用法

    定义用户model时可以给用户分配权限: class Meta: permissions = (       ("can_mark", "Can mark"), ...

  5. Python 2.7 学习笔记 模块和包

    我们来考虑下如下几种场景: 1.编写一个python程序,如果程序比较简单,则可以把代码放到一个python文件中.但如果程序功能比较多,可能需要多个python文件来组织源代码.而这些文件之间的代码 ...

  6. linux下find命令-atime,-ctime,-mtime真正含义

    linux下的-atime,-ctime,-mtime含义我们经常会在论坛或者群里面被问到,在linux或者unix下如何查看某文件的创建日期?经常又会有人说用find命令加选项-ctime,其实这里 ...

  7. 快速解决PDF文档加密不能打印问题_百度经验

    快速解决PDF文档加密不能打印问题_百度经验     快速解决PDF文档加密不能打印问题         |        浏览:182        |        更新:2014-01-06 1 ...

  8. libvirt(virsh命令介绍)

    有了virt-install是安装虚拟机的命令,当然也需要一个管理虚拟机的命令了,那就是virsh. virsh命令使用 virsh <command> <domain-id> ...

  9. 全栈project师的悲与欢

    从小米辞职出来创业的两个多月里,通过猎头或自己投简历,先后面试了知乎,今日头条,豌豆荚,美团,百度,App Annie,去哪儿,滴滴打车等技术团队,一二面(技术面)差点儿都轻松的过了,三面却没有毕业那 ...

  10. SQL之单行函数

    单行函数语法: function name(column|expression,[arg1,arg2,...]) 参数说明: function name:函数名称 column:数据库列名 expre ...