CodeForces 540C Program D

时间:2021-01-13 03:21:45

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

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

#include<iostream>  
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) typedef long long LL;
const int INF = (1<<30)-1;
const int mod=1000000007;
const int maxn=100005; char g[505][505];
int n,m,flag;
int st1,st2,en1,en2;
int dir[4][2]={1,0,-1,0,0,1,0,-1}; struct node{
int x,y;
}; void bfs()
{
node u;
u.x=st1;u.y=st2;
queue<node> q;
q.push(u); node v;
while(!q.empty())
   {
u=q.front();q.pop(); for(int i=0;i<4;i++)
     {
v.x=u.x+dir[i][0];
v.y=u.y+dir[i][1]; if(v.x==en1&&v.y==en2&&g[v.x][v.y]=='X')
       {
flag=1;
return;
}
if(v.x<1||v.x>n||v.y<1||v.y>m) continue;
if(g[v.x][v.y]=='X') continue; q.push(v);
g[v.x][v.y]='X';
}
}
} int main()
{
  
  scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
  cin>>g[i][j];
cin>>st1>>st2;
cin>>en1>>en2; flag=0;
bfs(); if(flag) printf("YES\n");
else printf("NO\n");
return 0;
}

CodeForces 540C Program D的更多相关文章

  1. CodeForces 540C Ice Cave (BFS)

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

  2. &lpar;简单广搜&rpar; Ice Cave -- codeforces -- 540C

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

  3. CodeForces 468A Program F

    Description Little X used to play a card game called "24 Game", but recently he has found ...

  4. CodeForces 534D Program B

    Description On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) ...

  5. CodeForces 540C Ice Cave &lpar;BFS&rpar;

    题意:给定 n * m的矩阵,让你并给定初始坐标和末坐标,你只能走'.',并且走过的'.'都会变成'X',然后问你能不能在末坐标是'X'的时候走进去. 析:这个题,在比赛时就是没做出来,其实是一个水题 ...

  6. CodeForces - 540C Ice Cave —— BFS

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

  7. 「日常训练」Ice Cave(Codeforces Round 301 Div&period;2 C)

    题意与分析(CodeForces 540C) 这题坑惨了我....我和一道经典的bfs题混淆了,这题比那题简单. 那题大概是这样的,一个冰塔,第一次踩某块会碎,第二次踩碎的会掉落.然后求可行解. 但是 ...

  8. Codeforces Round &num;443 &lpar;Div&period; 1&rpar; A&period; Short Program

    A. Short Program link http://codeforces.com/contest/878/problem/A describe Petya learned a new progr ...

  9. Codeforces Round &num;879 &lpar;Div&period; 2&rpar; C&period; Short Program

    题目链接:http://codeforces.com/contest/879/problem/C C. Short Program time limit per test2 seconds memor ...

随机推荐

  1. poj 3038

    http://poj.org/problem?id=3038 这个题我是在一个关于并查集的博客中找到的,结果我就觉得这个应该是个贪心,真想不出这个与并查集有什么鬼关系,看discuss里面也都是贪心, ...

  2. java 多线程(threadlocal)

    package com.example; import java.util.Random; public class App { public static class MyRunnable1 imp ...

  3. Winform开发框架重构总结

    最近一直致力于Winform开发框架的重构工作,因为发现要维护传统Winform开发框架.WCF开发框架.混合式开发框架,以及相关的模块,包括权限管理.字典管理模块.附件管理.人员管理等一些辅助模块, ...

  4. QQ在线咨询状态显示不出来怎么办?http&colon;&sol;&sol;bizapp&period;qq&period;com&sol;webpres&period;htm

  5. Python中pathlib模块

    Python中pathlib模块 Path.cwd():返回当前目录的路径 Path.home():返回当前用户的家目录 Path.stat():返回此路径信息 Path.touch():创建文件 P ...

  6. CSS垂直居中查询宝典

    一.垂直居中的用处 设计稿需求 当我们抱怨设计反复不定的时候,试着理解一下.每一位开发者也会是一位用户,请多多用'用户'的角色去开发.就比如下面这图,你会更稀饭哪种格式呢? 如果我们使用一个webap ...

  7. git分支错误提交导致代码丢失--窗口提示HEAD detached错误

    今天开发时git 检出分支到本地时操作错误,导致在一个临时分支上开发,且把代码提交了,结果代码未提交到任何分支,提交时还报了个错: HEAD detached at 4d927fa4 后来把代码重新检 ...

  8. Java POI 3&period;17写入、导入EXCEL性能测试

    我们先测试一下写入 50000 条 程序源码: 写入的excel文件信息 再看一下文件的结构 我们再次测试一下导入数据库的性能(用移动的网络上传至电信服务器): 在导入的过程中也可以中止导入行为: 上 ...

  9. JVM学习笔记-内存管理

    第一章 内存分配 1. 内存区域.     方法区和堆(线程共享),程序计数器 , VM栈 和 本地方法栈(线程隔离).     1) java虚拟机栈:线程私有.描写叙述的是java方法执行的内存模 ...

  10. 自己写操作系统---bootsector篇

    其实博主本来想在寒假自己写一个OSkernal的,高高兴兴的影印了本<一个操作系统的实现>. 然后又去图书馆借来<30天自制操作系统>和<X86/X64体系探索编程&gt ...