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[20];
//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=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
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("");
}
//**************************************************************************************string s[1000];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
struct node
{int x,y;int t;
};
int vis[1000][1000];
int main()
{int n=read(),m=read();for(int i=0;i<n;i++)cin>>s[i];node st,ed;cin>>st.x>>st.y;st.x--,st.y--;st.t=0;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=0;i<4;i++){node next=now;next.x+=dx[i];next.y+=dy[i];next.t++;if(next.x<0||next.x>=n||next.y<0||next.y>=m)continue;if(next.x==ed.x&&next.y==ed.y&&s[next.x][next.y]=='X'){printf("YES\n");return 0;}if(s[next.x][next.y]=='X')continue;q.push(next);s[next.x][next.y]='X';}}printf("NO\n");
}

Codeforces Round #301 (Div. 2) C. Ice Cave BFS相关推荐

  1. 贪心 Codeforces Round #301 (Div. 2) B. School Marks

    题目传送门 1 /* 2 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 3 num1是输出的1的个数,numy是除此之外的数都为 ...

  2. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  3. Codeforces Round #301 (Div. 2) B. School Marks 构造/贪心

    B. School Marks Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/probl ...

  4. Codeforces Round #301 (Div. 2) B. School Marks

    其实是很水的一道bfs题,昨晚比赛的时候没看清题意,漏了一个条件. 1 #include<cstdio> 2 #include<cstring> 3 #include<i ...

  5. Codeforces Round #245 (Div. 2): C. Xor-tree(BFS)

    题意: 给你一棵树,每个节点都有一个颜色,不是黑就是白,你每次可以选择一个节点,将这个节点的颜色翻转,同时这个点所有孙子的颜色也会全部被翻转,孙子的孙子颜色也会全部被翻转-- 问至少操作多少次使得所有 ...

  6. Codeforces Round #222 (Div. 2): C. Maze(BFS)

    题意: 给你一个n*m的迷宫,'.'是路,'#'是墙,输入保证所有的'.'构成一个联通块,要求为这个迷宫再添加k面墙,使得剩下所有的'.'仍然构成一个联通块 思路:反过来处理,先将所有的'.'全部变成 ...

  7. CodeCraft-19 and Codeforces Round #537 (Div. 2)解题报告

    Codeforces Round #537 (Div. 2) 题解报告 A. Superhero Transformation 题意 问能否通过把辅音字母换成另一个辅音字母,元音字母换成另一个元音字母 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. 快速搭建一个基于知识图谱的智能问答系统
  2. 图形驱动程序和显卡驱动什么区别_我们常说的计算机驱动程序到底是什么,深入解读驱动程序本质...
  3. 因滚动条出现而导致页面晃动的解决方案
  4. 计算机风冷散热系统的原理,显卡“发烧”的原因_显卡散热原理
  5. SQL语句中timestamp进行排序BUG
  6. vue从其它页面返回_vue页面按返回键等跳转重定向判断
  7. mybatis学习(3):映射文件的配置和接口创建
  8. spring Boot环境下dubbo+zookeeper的一个基础讲解与示例
  9. 从mysql数据库读取Blob_读取数据库Blob类型的文本数据
  10. vector, list, deque的使用区别
  11. 学php什么自考专业,什么自考专业容易过自学考试哪些专业好考(已帮助356690人)...
  12. 各型号英特尔CUP的功率
  13. php实现根据身份证获取年龄的函数
  14. 网络安全阶段一学习笔记
  15. 谈谈两个互联网大佬的「认知革命」
  16. java info()方法_Java中的提供者getInfo()方法
  17. 优秀的云计算工程师需要学什么?云计算Docker学习路线
  18. Mac系统如何制作Mac U盘启动盘(更新至mac 12.6)
  19. 最大公约数简便算法_最大公约数算法
  20. Android 显示文字超过指定长度部分使用省略号表示

热门文章

  1. leetcode383. 赎金信
  2. leetcode145. 二叉树的后序遍历 意想不到的骚操作
  3. 简单暴力到dp的优化(初级篇)
  4. C++(STL):14--- forward_list比list更高效的容器
  5. 《Python Cookbook 3rd》笔记(2.1):使用多个界定符分割字符串
  6. 写出表格的结构html,一个面试题,根据json结构生成html表格
  7. 3分钟入门python_3分钟带你了解世界第一语言Python 入门上手也这么简单!
  8. 实际操作之路考的这些事
  9. OpenCL 与 CUDA
  10. 遍历Map key-value的两种方法、遍历Set方法