Ice Cave

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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

Hint(看下面)

In the first sample test one possible path is:

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

BFS搜索!!很明显了!

要注意的是冰块踩过会变成X,下一次踩就会掉下去。

题解:pair是一种模板类型,其中包含两个数据值,两个数据的类型可以相同可以不同 ,由于pair类型的使用比较繁琐,因为如果要定义多个形同的pair类型的时候,可以时候typedef简化声明:
typedef pair<int, int>p;p中含有2个整型数

#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
typedef pair<int, int> p;
int dx[]= { , -, , };
int dy[]= { , , , - };
int n,m;
int r1,c1,r2,c2;
char a[][];
int bfs()
{
queue<p> q;
q.push(p(r1,c1));
a[r1][c1]='X'; //第一步上去冰块已碎
while(!q.empty())
{
r1=q.front().first;
c1=q.front().second;
q.pop();
for(int i=; i<; i++)
{
int xx=r1+dx[i];
int yy=c1+dy[i];
if( xx<||xx>=n||yy<||yy>=m)
continue;
if(a[xx][yy]=='X')
{
//到达点也会碎
if(xx==r2 && yy==c2)
return ;
continue;
}
a[xx][yy]='X'; //走了之后就变成易碎的冰块
q.push(p(xx,yy));
}
}
return ;
}
int main()
{
int ans;
while(cin>>n>>m)
{
for(int i=; i<n; i++)
cin>>a[i];
cin>>r1>>c1>>r2>>c2;
r1--; //用的二维数组是从0~n-1,而输入的是1~n,所以都要减1
c1--;
r2--;
c2--;
ans=bfs();
if(ans)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return ;
}

Codeforces 301_div.2_Ice Cave(BFS走冰块)的更多相关文章

  1. BFS学习 Codeforces 301_div.2_Ice Cave

    C. Ice Cave time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  2. CodeForces 540C Ice Cave (BFS)

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

  3. CodeForces - 540C Ice Cave —— BFS

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

  4. CodeForces 540C Ice Cave (BFS)

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

  5. 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 ...

  6. Vladik and Favorite Game CodeForces - 811D (思维+BFS+模拟+交互题)

    D. Vladik and Favorite Game time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. Fair CodeForces - 987D(巧妙bfs)

    题意: 有n个城市 m条边,每条边的权值为1,每个城市生产一种商品(可以相同,一共k种),求出分别从每个城市出发获得s种商品时所走过路的最小权值 解析: 我们倒过来想,不用城市找商品,而是商品找城市, ...

  8. codeforces 1072D Minimum path bfs+剪枝 好题

    题目传送门 题目大意: 给出一幅n*n的字符,从1,1位置走到n,n,会得到一个字符串,你有k次机会改变某一个字符(变成a),求字典序最小的路径. 题解: (先吐槽一句,cf 标签是dfs题????) ...

  9. Knight Moves(BFS,走’日‘字)

    Knight Moves Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

随机推荐

  1. Apache HBase 2015年发展回顾与未来展望

    编者按:高可用架构推出 2015 年度回顾系列文章,分享在架构领域具有典型意义的年度案例,本文由张虔熙分享.转载请注明来自高可用架构公众号「ArchNotes」.   张虔熙,Hulu 网,专注于分布 ...

  2. Log4j自定义Appender介绍

    转自:http://gemantic.iteye.com/blog/1234996 最初想要在执行一段业务逻辑的时候调用一个外部接口记录审计信息,一直找不到一个比较优雅的方式,经过讨论觉得log4j自 ...

  3. BDD框架之lettuce---python3.+安装报错

    跟虫师学习python,学到BDD框架之lettuce( http://www.cnblogs.com/fnng/p/3415609.html),发现python3.5环境下安装lettuce后无法正 ...

  4. Hadoop 的子项目

    Hadoop Common: 在0.20及以前的版本中,包含HDFS.MapReduce和其他项目公共内容,从0.21开始HDFS和MapReduce被分离为独立的子项目,其余内容为Hadoop Co ...

  5. Windows7下32位IE异常不能打开解决方法

    今天更新了Update及安装了一些软件,重启电脑后发现32位IE不能正常打开,而64位IE正常. 错误信息如下: 问题签名:  问题事件名称: BEX  应用程序名: iexplore.exe  应用 ...

  6. 严苛模式(StrictMode)

    Android 2.3提供一个称为严苛模式(StrictMode)的调试特性,Google称该特性已经使数百个Android上的Google应用程序受益.那它都做什么呢?它将报告与线程及虚拟机相关的策 ...

  7. [AngularJS] Enable Animations Explicitly For A Performance Boost In AngularJS

    http://www.bennadel.com/blog/2935-enable-animations-explicitly-for-a-performance-boost-in-angularjs. ...

  8. 在Linux上怎么安装和配置Apache Samza

    samza是一个分布式的流式数据处理框架(streaming processing),它是基于Kafka消息队列来实现类实时的流式数据处理的.(准确的说,samza是通过模块化的形式来使用kafka的 ...

  9. 模板-->欧几里得算法

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 简单的测试 None 代码模板 /* * TIME complexity:O(logN) means very fast. ...

  10. 使用Navicat或PLSQL客户端工具连接远程Oracle数据库(本地无需安装oracle)

    1.首先下载好客户端工具,然后到Oracle官网下载Instant Client: http://www.oracle.com/us/solutions/index-097480.html 解压文件到 ...