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. 数据结构C语言版 表插入排序 静态表

    数据结构C语言版 表插入排序.txt两个人吵架,先说对不起的人,并不是认输了,并不是原谅了.他只是比对方更珍惜这份感情./*  数据结构C语言版 表插入排序  算法10.3 P267-P270  编译 ...

  2. 单实例支撑每天上亿个请求的SSDB

    SSDB 是一个 C++ 开发的 NoSQL 存储服务器, 支持 zset, map 数据结构, 可替代 Redis, 特别适合存储集合数据. SSDB 被开发和开源出来后, 已经在生产环境经受了3个 ...

  3. Codeforces Round #312 (Div. 2)

    好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价 ...

  4. Android的BUG(四) - Android app的卡死问题

    做android,免不了要去运行一些跑分程序,常用的跑分程序有quadrant(象限),nbench,安兔兔等.作为系统工程师,对这些跑分 程序都非常的不屑,这个只能是一个不客观的参考,但客户都喜欢拿 ...

  5. Android内存之VSS/RSS/PSS/USS

    Terms VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存) RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存) PSS - P ...

  6. Sort List 分类: leetcode 算法 2015-07-10 15:35 1人阅读 评论(0) 收藏

    对链表进行排序,要求时间复杂度为O(n log n) ,不使用额外的空间. 我一开始的想法是借助quicksort的思想,代码如下: # time O(nlog(n)) # Definition fo ...

  7. 相邻数字的基数等比确定进制问题pojg2972

    解决数制转换问题时,如果所给的数值不是用十进制表示的,一般用一个字符型数组来存放,数组的每个元素分别存储它的一位数字.然后按位转换求和,得到十进制表示,再把十进制转成成其他所求的进制表示.转成的结果也 ...

  8. STL 源代码剖析 算法 stl_algo.h -- equal_range

    本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie equal_range(应用于有序区间) ------------------------- ...

  9. 动态链接库dll的 静态加载 与 动态加载

    dll 两种链接方式  : 动态链接和静态链接(链接亦称加载) 动态链接是指在生成可执行文件时不将所有程序用到的函数链接到一个文件,因为有许多函数在操作系统带的dll文件中,当程序运行时直接从操作系统 ...

  10. 使用 HTML5 webSocket API实现即时通讯的功能

    project下载地址:http://download.csdn.net/detail/wangshuxuncom/6430191 说明: 本project用于展示怎样使用 HTML5 webSock ...