链接: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. WPF学习11:基于MVVM Light 制作图形编辑工具(2)

    本文是WPF学习10:基于MVVM Light 制作图形编辑工具(1)的后续 这一次的目标是完成 两个任务. 画布 效果: 画布上,选择的方案是:直接以Image作为画布,使用RenderTarget ...

  2. P1478 陶陶摘苹果(升级版)

    题目描述 又是一年秋季时,陶陶家的苹果树结了n个果子.陶陶又跑去摘苹果,这次她有一个a公分的椅子.当他手够不着时,他会站到椅子上再试试. 这次与NOIp2005普及组第一题不同的是:陶陶之前搬凳子,力 ...

  3. java urlEncode 和urlDecode的用法

    前台进行http请求的时候 如果要对中问进行编码,要使用两次编码 String zhName=urlEncode.encode((urlEncode.encode("中文",&qu ...

  4. Sql Server 2012 事务复制遇到的问题及解决方式

    1.订阅服务器提示:作业失败.无法确定所有者 WIN-01Q6JB46CHV\Administrator(拥有作业XXX)是否有服务器访问权限(原因:无法获取有关 Windows NT 组/用户'WI ...

  5. 手动配置webpack

    //注:“__dirname”是node.js中的一个全局变量,它指向当前执行脚本所在的目录.const path = require('path');const webpack = require( ...

  6. CAD控件,CAD插件使用教程:Android开发使用控件--开发环境的搭建

    Android开发使用控件入门--环境搭建 2014-12-24 09:57     14人阅读     评论(0)     收藏         编辑     删除 CAD控件.CAD三维控件,手机 ...

  7. opencv读图片错误,已解决

    could not loag image... terminate called after throwing an instance of 'cv::Exception' what(): OpenC ...

  8. -- HTML标记大全参考手册[推荐]

    --  HTML标记大全参考手册[推荐]总类(所有HTML文件都有的) 文件类型 <HTML></HTML> (放在档案的开头与结尾) 文件主题 <TITLE>&l ...

  9. JS如何禁用浏览器的退格键

    <script type="text/javascript"> //处理键盘事件 禁止后退键(Backspace)密码或单行.多行文本框除外 function forb ...

  10. Chrome插件:浏览器后台与页面间通信

    content.js 与 background.js和popup.js 通信和 background.js与popup.js  这些通信都用 chrome.runtime.sendMessage 这个 ...