ice cave
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
YES
5 4
.X..
...X
X.X.
....
.XX.
5 3
1 1
NO
4 7
..X.XX.
.XX..X.
X...X..
X......
2 2
1 6
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的更多相关文章
- DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...
- (简单广搜) Ice Cave -- codeforces -- 540C
http://codeforces.com/problemset/problem/540/C You play a computer game. Your character stands on so ...
- CodeForces 540C Ice Cave (BFS)
http://codeforces.com/problemset/problem/540/C Ice Cave Time Limit:2000MS Memory Limit:262 ...
- 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 ...
- CF#301 C:Ice Cave(简单BFS)
C:Ice Cave 有一个m*n的地图,里面包含'.'表示完整的冰块,'X'表示有裂痕的冰块,当游戏者到达完整的冰块时,这个位置的冰块会变成有裂痕的冰块,如果到达有裂痕的冰块时,游戏者会进入下一关 ...
- CodeForces - 540C Ice Cave —— BFS
题目链接:https://vjudge.net/contest/226823#problem/C You play a computer game. Your character stands on ...
- ICE CAVE(BFS搜索(模拟))
Description You play a computer game. Your character stands on some level of a multilevel ice cave. ...
- 540C: Ice Cave
题目链接 题意: n*m的地图,'X'表示有裂痕的冰块,'.'表示完整的冰块,有裂痕的冰块再被踩一次就会碎掉,完整的冰块被踩一次会变成有裂痕的冰块, 现在告诉起点和终点,问从起点能否走到终点并且使终点 ...
- CodeForces 540C Ice Cave (BFS)
题意:给定 n * m的矩阵,让你并给定初始坐标和末坐标,你只能走'.',并且走过的'.'都会变成'X',然后问你能不能在末坐标是'X'的时候走进去. 析:这个题,在比赛时就是没做出来,其实是一个水题 ...
随机推荐
- 笔记之Cyclone IV第一卷第三章器件中的存储器模块
嵌入式存储器结构由一列列 M9K 存储器模块组成,通过对这些 M9K 存储器模块进行配置,可以实现各种存储器功能,例如:RAM.移位寄存器. ROM 以及FIFO 缓冲器. M9K 存储器模块支持以下 ...
- FLUSH TABLES WITH READ LOCK 锁全局
[root@wx03 ~]# cat a3.sh mysql -uroot -p1234567<<eof use scan; FLUSH TABLES WITH READ LOCK; sy ...
- Jekyll搭建过程详解
原先博客用Jekyll搭建在Github上,近来访问缓慢,而且markdown不太方便写,故决定在博客园安个新家. 文章见Github博客: 搭建过程:http://wuxichen.github.i ...
- [置顶] jeecg-framework-3.3.2-RELEASE 最新版本发布
平台介绍 JEECG(J2EE CodeGeneration)是一款基于代码生成器的智能开发平台,引领新开发模式(OnlineCoding模式->代码生成器模式->手工MERGE智能开 ...
- Http的操作(不传递参数)
ttpResponse httpResponse = null; HttpEntity httpEntity = null; HttpGet httpGet = new HttpGet ...
- Linux之shell编程基础
一.变量 变量在shell中分为:本地变量.环境变量.位置参数: 本地变量:仅可在用户当前shell生命期的脚本中使用的变量,本地变量随着shell进程的消亡而无效,本地变量在新启动的shell中依旧 ...
- Android模拟器的文件目录介绍
文件存放在 .avd文件夹下 .ini为对应的配置文件 打开.avd文件夹 *.lock文件夹保存的是模拟器的一下数据,当模拟器正常关闭时这些文件夹都会被自动删除. 当模拟器无法开启的时候可以 ...
- CSS - 解决使用浮动,父窗体不能撑高问题
浮动的父级元素一定要用 clear 清除浮动,否则高度会无法撑开.
- Gas Station|leetcode 贪心
贪心:尽量将gas[i]-cost[i]>0的放在前面,gas[i]-cost[i]<0的放在后面.(路程的前面有汽油剩下,耗汽油的放在路程的后面). 能否全程通过的 条件 是:sum(g ...
- 极光IM使用教程-极光推送
链接地址:http://jingyan.baidu.com/article/a948d65178a6ea0a2ccd2e7e.html 极光IM使用教程,如果您的 App 需要同时集成 Push 功能 ...