题目连接:http://codeforces.com/problemset/problem/540/C

C. Ice Cave
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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'.

Examples
Input
4 6X...XX...XX..X..X.......1 62 2
Output
YES
Input
5 4.X.....XX.X......XX.5 31 1
Output
NO
Input
4 7..X.XX..XX..X.X...X..X......2 21 6
Output
YES

题目大意:给定一个矩阵,由"."和"X"组成,分别代表完整的冰块和裂缝的冰块,完整的冰块走过一次就会变成裂缝的冰块,裂缝的冰块走过就会掉下去,给定起点和终点,在保证不会掉下去的情况下,问能否从起点走到终点恰好在终点掉下去。解题思路:dfs裸题,因为不需要找多条路径,所以对于每个节点,若经过它的某一条路径能寻找到结果,则必定会在第一次经过该点时就找到,所以不需要重置已经走过的路线,所以暴力dfs即可,每次走可走的完整冰块,完整冰块走过以后置为裂缝冰块,最后得出结果即可。

代码如下:
#include<bits/stdc++.h>

using namespace std;

][];
int n,m,sx,sy,ex,ey;
]= {,,,-,,};
]= {,,,,-,};
;

void dfs(int x,int y)
{
    cout<<"x="<<x<<"y="<<y<<endl;
    if(g[x][y]=='.')
        g[x][y]='X';
    ; u<=; u++)
    {
        int a=x+fx[u];
        int b=y+fy[u];
        &&b<=m&&b>=)
        {
            if(g[a][b]=='.')
            {
                dfs(a,b);
            }
            else
            {
                if(a==ex&&b==ey)
                {
                    flag=;
                    return;
                }
                else
                    continue;
            }
        }
    }
    return;
}

int main()
{
    cin>>n>>m;
    ];
    ; i<=n; i++)
    {
        scanf("%s",in);
        ; j<=m; j++)
            g[i][j]=];
    }
    cin>>sx>>sy;
    cin>>ex>>ey;
    dfs(sx,sy);
    if(flag)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}

codeforces-540C的更多相关文章

  1. CodeForces 540C Ice Cave (BFS)

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

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

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

  3. CodeForces 540C Program D

    Description You play a computer game. Your character stands on some level of a multilevel ice cave. ...

  4. CodeForces 540C Ice Cave (BFS)

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

  5. CodeForces - 540C Ice Cave —— BFS

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

  6. 「日常训练」Ice Cave(Codeforces Round 301 Div.2 C)

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

  7. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  8. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  9. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  10. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

随机推荐

  1. Jenkins拾遗--第四篇-适当的让构建失败

    问题的引出: 有一段我们的前端构建总会现git上分支名称中的版本号和工程里的版本号不一致的问题:这样会导致构一个问题:构建后的产品名称叫做1.1,但是进入app的关于页面,看到的版本还是1.0.这会让 ...

  2. WPF 利用键盘钩子来捕获键盘,做一些不为人知的事情...完整实例

    键盘钩子是一种可以监控键盘操作的指令. 看到这句话是不是觉得其实键盘钩子可以做很多事情. 场景 当你的程序需要一个全局的快捷键时,可以考虑使用键盘钩子,如大家常用qq的截图快捷键,那么在WPF里怎么去 ...

  3. PyCharm 解决有些库(函数)没有代码提示

    问题描述: 如图,当输入 im. 没有智能提示第三库相应的函数或其他提示. 解决方案: python是动态强类型语言,IDE无法判断Image.open("panda.png")的 ...

  4. Kotlin将Realm提升到更高层次

    作者:Víctor Manuel Pineda 时间:Feb 14, 2017 原文链接:https://antonioleiva.com/kotlin-realm-extensions/ 当有人问我 ...

  5. Opencv3.2.0安装包

    这个资源是Opencv3.2.0安装包,包括Windows软件包,Android软件包,IOS软件包,还有opencv的源代码:需要的下载吧. 点击下载

  6. SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'XXX' (13)

    SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'XXX' (13) 我可以真见识了 SELinux 的利害了, 这个问题让我找了好长时 ...

  7. 搭建springmvc项目404,没扫描到包

    搭建简单项目完成之后,曾经出现过一个问题 跳转报了404,控制台忘了没留啊... 反正意思就是说我配置有问题,导致没有扫描到注释的类 <context:component-scan base-p ...

  8. 基于HTTP协议的轻量级开源简单队列服务:HTTPSQS[转]

    HTTPSQS(HTTP Simple Queue Service)是一款基于 HTTP GET/POST 协议的轻量级开源简单消息队列服务,使用 Tokyo Cabinet 的 B+Tree Key ...

  9. Nginx与Tomcat集成

    Nginx用来处理静态页面的请求,JSP交给Tomcat处理 安装JDK 安装后,配置好JAVA_HOME和PATH Mac查看JAVA_HOME路径的方法:/usr/libexec/java_hom ...

  10. P4305 [JLOI2011]不重复数字

    题目描述 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4. ...