C. Ice Cave

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/540/problem/C

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

4 6
X...XX
...XX.
.X..X.
......
1 6
2 2

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

题意

有一个矩形区域,一开始你在一个地方,你只能走.的位置,走了之后.就会变成X,然后你必须让终点变成x,然后再走上去

问你可不可行

题解:

BFS搞一搞就好了,裸题= =

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //§ß§é§à§é¨f§³
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** string s[];
int dx[]={,-,,};
int dy[]={,,,-};
struct node
{
int x,y;
int t;
};
int vis[][];
int main()
{
int n=read(),m=read();
for(int i=;i<n;i++)
cin>>s[i];
node st,ed;
cin>>st.x>>st.y;
st.x--,st.y--;
st.t=;
cin>>ed.x>>ed.y;
ed.x--,ed.y--;
queue<node> q;
q.push(st);
while(!q.empty())
{
node now=q.front();
q.pop();
for(int i=;i<;i++)
{
node next=now;
next.x+=dx[i];
next.y+=dy[i];
next.t++;
if(next.x<||next.x>=n||next.y<||next.y>=m)
continue;
if(next.x==ed.x&&next.y==ed.y&&s[next.x][next.y]=='X')
{
printf("YES\n");
return ;
}
if(s[next.x][next.y]=='X')
continue;
q.push(next);
s[next.x][next.y]='X';
}
}
printf("NO\n");
}

最新文章

  1. [原创]java WEB学习笔记92:Hibernate学习之路-- -QBC 检索和本地 SQL 检索:基本的QBC 查询,带 AND 和 OR 的QBC,统计查询,排序,分页
  2. Git学习笔记(持续更新)
  3. js-jQuery对象与dom对象相互转换
  4. phpcms v9 企业黄页加入企业会员提示“请选择企业库类型!”
  5. SQL Server2008创建约束图解 转
  6. C语言杂记
  7. 牛刀小试、用SharePoint 实现请假管理功能
  8. BZOJ 1057 棋盘制作
  9. Twitter Storm源代码分析之Nimbus/Supervisor本地目录结构
  10. Codeforces Round #363 (Div. 2) C. Vacations(DP)
  11. iOS 调试 之 打印
  12. matlab中的sub2ind函数
  13. 实验效果展示(会声会影+FSCapture)
  14. SharePoint 已在此服务器场中安装 ID 为 XXXXXXXXX 的功能。请使用强制属性显式地重新安装此功能。解决方法
  15. android异步任务处理(网络等耗时操作)
  16. Win10激活密钥key(可激活所有版本)
  17. (后端)Spring手动回滚事务
  18. Csharp—碎片知识积累
  19. T-SQL ORDER BY子句 排序方式
  20. JAVA常用工具类汇总

热门文章

  1. cookie 跨域的问题
  2. Class.this 和 this 的有什么不同
  3. #题目:有10 台被监控主机、一台监控机,在监控机上编写脚本,一旦某台被监控机器/ 分区适用率大于80%, 就发邮件报警放到crontab 里面, 每10 分钟检查一次
  4. 初探Nginx架构
  5. 1、CentOS 6 安装GitLab
  6. 关于函数strtok和strtok_r的使用要点和实现原理
  7. 20165301陈潭飞2017-2018-2 20165301 实验三《Java面向对象程序设计》实验报告
  8. hive学习(四) hive的函数
  9. Flyweight模式(亨元模式)
  10. Coding.net进阶,使用Git管理代码