链接:http://codeforces.com/problemset/problem/540/C

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 test(s)
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
Note

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’表示碎冰   ‘.'便是完整的冰下面简称好冰

好冰走过一次会变成碎冰      碎冰走过一次破了  毁掉下去

现在给你起点和终点   然后看是否能从起点走到终点然后再终点掉下去。

分析:

典型的搜索

但是就是判断条件难了点,,我写的时候调试了好长时间终于A了

#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std; #define INF 0xfffffff
#define N 700
int d[][]={{,},{-,},{,},{,-}};
int vis[N][N];
char maps[N][N];
struct node
{
int x,y;
}s,e,p; int bfs(int n,int m)
{
queue<node>Q;
Q.push(s);
memset(vis,,sizeof(vis));
vis[s.x][s.y]=;
while(!Q.empty())
{
node u,v;
u=Q.front();
Q.pop(); for(int i=;i<;i++)
{
v.x=u.x+d[i][];
v.y=u.y+d[i][];
if(maps[v.x][v.y]=='X' && v.x==e.x && v.y==e.y)
return ;
if(maps[v.x][v.y]=='.' && v.x>= && v.y>= && v.x<n && v.y<m && !vis[v.x][v.y])
{
Q.push(v);
vis[v.x][v.y]=;
maps[v.x][v.y]='X';
}
}
}
return ;
} int main()
{
int n,m,i,s1,e1,s2,e2;
while(scanf("%d %d",&n,&m)!=EOF)
{
memset(maps,,sizeof(maps));
for(i=;i<n;i++)
{
scanf("%s",maps[i]);
}
scanf("%d %d %d %d",&s1,&e1,&s2,&e2);
s.x=s1-;
s.y=e1-;
e.x=s2-;
e.y=e2-;
if(bfs(n,m)==)
printf("YES\n");
else
printf("NO\n");
}
return ;
}

Ice Cave-CodeForces(广搜)的更多相关文章

  1. (简单广搜) Ice Cave -- codeforces -- 540C

    http://codeforces.com/problemset/problem/540/C You play a computer game. Your character stands on so ...

  2. DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

    题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...

  3. 『ice 离散化广搜』

    ice(USACO) Description Bessie 在一个冰封的湖面上游泳,湖面可以表示为二维的平面,坐标范围是-1,000,000,000..1,000,000,000. 湖面上的N(1 & ...

  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. CodeForces 682C Alyona and the Tree(广搜 + 技巧)

    方法:从根节点开始广搜,如果遇到了应该删除的点,就再广搜删掉它的子树并标记,然后统计一下被标记的个数就是答案,所谓技巧就是从根节点开始搜索的时候,如果遇到了某个节点的距离<0,就让它是0,0可以 ...

  7. CodeForces - 540C Ice Cave —— BFS

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

  8. Codeforces 1105D(双层广搜)

    要点 题意:可以拐弯,即哈密顿距离 注意不可以直接一个一个搜,这过程中会把下一轮的标记上,导致同一轮的其它点没能正常完成应有的搜索 因此采用双层广搜,把同一轮先都出队列再的一起搜 #include & ...

  9. CF520B——Two Buttons——————【广搜或找规律】

    J - Two Buttons Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

随机推荐

  1. ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第五天(非原创)

    文章大纲 一.课程介绍二.前台系统(门户系统)搭建介绍三.前台系统(门户系统)搭建实战四.js请求跨域解决五.项目源码与资料下载六.参考文章   一.课程介绍 一共14天课程(1)第一天:电商行业的背 ...

  2. AJPFX总结面向对象思想设计原则

    面向对象思想设计原则   A.单一职责原则           其实就是开发人员经常说的”高内聚,低耦合”           也就是说,每个类应该只有一个职责,对外只能提供一种功能,而引起类变化的原 ...

  3. CF792C Divide by Three

    思路: dp. 实现: #include <iostream> #include <cstdio> #include <cstring> #include < ...

  4. Android开发中使用代码删除数据库

    更多信息参考:Android开发中使用代码删除数据库 在Android开发中,如果用到数据库,就会有一个很麻烦的问题,就是有时候需要删除数据库很麻烦,要打开Android Device Monitor ...

  5. MTK处理器手机 解锁Bootloader 教程

    目前很多手机都需要解锁Bootloader之后才能进行刷机操作   本篇教程教你如何傻瓜式解锁Bootloader 首先需要在设置-关于手机 找到版本号(个别手机可能是内核版本号,甚至其他) 然后 快 ...

  6. Android习惯--Activity启动方法

    public void Text extends Activity{ public void static actionStart(Context context, int i, String str ...

  7. hexo_config.yml配置内容

    # Hexo Configuration ## Docs: https://hexo.io/docs/configuration.html ## Source: https://github.com/ ...

  8. xxtea 文件加密与解密

    加密 cocos luacompile -s src -d dst_dir -e -b xxxxx -k xxxxx --disable-compile 解密 cocos luacompile -s ...

  9. JavaSE-18 常用工具类

    学习要点 Object类 枚举 包装类 Math类 Random类 字符串处理 日期时间 Object类 1  什么是Object类 Object类存储在java.lang包中,是所有java类(Ob ...

  10. centos下安装redis(记录其中踩坑的过程)

    一.先下载到redis-3.0.4.tar.gz包(本文以3.0.4版本为例) 我将这个包放在/opt目录下,在/opt下并解压这个包 tar -zxvf redis-.tar.gz 然后进入redi ...