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.

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
using namespace std; #define N 550 char G[N][N];
int a[N][N], n, m;
int dir[][] = {{-,},{,-},{,},{,}}; struct node
{
int x, y;
}Start, End; int BFS()
{
int i;
node p, q; queue<node>Q;
Q.push(Start); ///a[Start.x][Start.y]--; 由于题意理解错误, 死在了这里 while(Q.size())
{
p = Q.front(), Q.pop(); for(i=; i<; i++)
{
q.x = p.x + dir[i][];
q.y = p.y + dir[i][]; if(q.x==End.x && q.y==End.y && a[q.x][q.y]==) return ; if(q.x>= && q.x<n && q.y>= && q.y<m && a[q.x][q.y]==)
{
a[q.x][q.y]--;
Q.push(q);
}
}
} return ;
} int main()
{
int i, j;
scanf("%d%d", &n, &m); memset(G, , sizeof(G));
memset(a, , sizeof(a)); for(i=; i<n; i++)
{
scanf("%s", G[i]);
for(j=; j<m; j++)
{
if(G[i][j] == 'X')
a[i][j] = ;
if(G[i][j] == '.')
a[i][j] = ;
}
} scanf("%d%d", &Start.x, &Start.y);
scanf("%d%d", &End.x, &End.y); Start.x--, Start.y--;
End.x--, End.y--; int ans = BFS(); if(ans)
printf("YES\n");
else
printf("NO\n"); return ;
}

(简单广搜) Ice Cave -- codeforces -- 540C的更多相关文章

  1. POJ 3126 Prime Path 简单广搜(BFS)

    题意:一个四位数的质数,每次只能变换一个数字,而且变换后的数也要为质数.给出两个四位数的质数,输出第一个数变换为第二个数的最少步骤. 利用广搜就能很快解决问题了.还有一个要注意的地方,千位要大于0.例 ...

  2. POJ1376简单广搜

    题意:       给你一个n*m的矩阵,然后给你机器人的起点和终点,还有起点的方向,然后每次机器人有两种操作,左右旋转90度,或者是朝着原来的方向走1,2或者3步,机器人再走的过程中不能碰到格子,也 ...

  3. hdu 2612(Find a way)(简单广搜)

    Find a way Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Su ...

  4. 简单广搜,迷宫问题(POJ3984)

    题目链接:http://poj.org/problem?id=3984 解题报告: 1.设置node结构体,成员pre记录该点的前驱. 2.递归输出: void print(int i) { ) { ...

  5. poj 3278:Catch That Cow(简单一维广搜)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 45648   Accepted: 14310 ...

  6. hdu 2612:Find a way(经典BFS广搜题)

    Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. CodeForces 540C Ice Cave (BFS)

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

  8. CodeForces - 540C Ice Cave —— BFS

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

  9. 『ice 离散化广搜』

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

随机推荐

  1. 使用 gitbook 写东西

    会了markdown 不会用gitbook怎么可以呢 先安装 npm install gitbook -g npm install gitbook-cli -g cli使用代码是客户端的意思,要牢记 ...

  2. js call方法的使用

    转自:js call call 方法 请参阅 应用于:Function 对象 要求 版本 5.5 调用一个对象的一个方法,以另一个对象替换当前对象. call([thisObj[,arg1[, arg ...

  3. (转)关于X64位系统IIS7下支持32位asp.net程序

    最近在windows2008 x64位系统下的IIS7下部署asp.net程序. vs2005或vs2008默认的情况下是Any cpu 的也就是支持x86和x64两种系统的.可我的程序在引用了一个三 ...

  4. Android.Tools.Eclipse hangs at the Android SDK Content Loader

    Eclipse hangs at the Android SDK Content Loader http://stackoverflow.com/questions/13489141/eclipse- ...

  5. (O)编写可维护的代码示例(原创)

    图片轮播: /*广告图片数组*/ var imgs=[ {"i":0,"img":"images/index/banner_01.jpg"} ...

  6. Shell脚本中$0、$?、$!等的意义

    变量说明$$ Shell本身的PID(ProcessID)$! Shell最后运行的后台Process的PID$? 最后运行的命令的结束代码(返回值)$- 使用Set命令设定的Flag一览$* 所有参 ...

  7. shell脚本${}、##和%%使用范例

    file=/dir1/dir2/dir3/my.file.txt 可以用${ }分别替换得到不同的值: ${file#*/}:删掉第一个 / 及其左边的字符串:dir1/dir2/dir3/my.fi ...

  8. 使用iTEXT库生成pdf

    iTEXT下载地址 https://sourceforge.net/projects/itext/files/ 选择绿色的按钮,下载最新版本,解压后是一些jar包 为了使用方便,将文件夹放到JAVA_ ...

  9. Spring 如何保证后置处理器的执行顺序 - OrderComparator

    Spring 如何保证后置处理器的执行顺序 - OrderComparator Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.htm ...

  10. Python之路(第二十一篇) re模块

    一.re模块 正则表达式本身是一种小型的.高度专业化的编程语言,正则表达式就是字符串的匹配规则,在多数编程语言里都有相应的支持,python里对应的模块是re,正则表达式模式被编译成一系列的字节码,然 ...