题目连接: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. 【HTML&CSS】 第一章:DTD文档声明

    <!DOCTYPE> 声明必须是 HTML 文档的第一行,位于 <html> 标签之前. <!DOCTYPE> 声明不是 HTML 标签:它是指示 web 浏览器关 ...

  2. 4G来临,短视频社交分享应用或井喷

    因为工作的原因,接触短视频社交应用的时间相对较多,不管是自家的微视,还是别人家的Vine.玩拍.秒拍等,都有体验过.随着时间的推移,我愈发感受到有一股似曾相识的势能正在某个地方慢慢积聚,直到今天我才猛 ...

  3. 恢复误删除表黑科技之relay log大法

      Preface       In my previous blogs,I've demonstrated several mothods of how to rescue a dropped ta ...

  4. (原、整)Unreal源码 CoreUbject- Uobject

    (原.整) Unreal源码 CoreUbject- Uobject 类别                    [随笔分类]Unreal源码搬山 @author:白袍小道 随缘那啥 这里还是属于UE ...

  5. Android记事本11

    昨天: Activity的启动模式. 今天: 分析了一些网上的例子的源码. 遇到问题: 无.

  6. 初识 HTML5(一)

    H5其实就是H4的一个增强版本,我们在利用H5进行网页的构造会更简便,标签语义更简洁明了.首先,我们要理解HTML4,它是HTML的标记+css2+JavaScript的一些基本应用,简言之,就是AP ...

  7. gulp入门1

    1. 下载.安装git(https://git-scm.com/downloads),学会使用命令行. 2. 下载.安装node.js(https://nodejs.org/en/),现在node.j ...

  8. Linux下磁盘管理

    设置密码mkpasswdmkpasswd -s 0mkpasswd -s 0 -1 15 规定密码的长度 1. 查看磁盘或者目录的容量df 查看磁盘各分区使用情况 不加参数以k为单位 df -i in ...

  9. 仿今日头条按钮loading效果

    效果 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  10. POJ2175:Evacuation Plan(消负圈)

    Evacuation Plan Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 5665Accepted: 1481Special J ...