题目连接: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. 【UVA10655】 Contemplation! Algebra

    题目 给定 \(p = a + b\) 和 \(q = ab\) 和 \(n\),求 \(a ^ n + b ^ n\). $0\le n\lt 2^{63} $ 分析 大水题. 先考虑 \(n\) ...

  2. (转\整)UE4游戏优化 多人大地型游戏的优化(二)渲染线程的优化

    施主分享随缘,评论随心,@author:白袍小道 小道暗语: 1.因为小道这里博客目录没自己整,暂时就用随笔目录结构,所以二级目录那啥就忽略了.标题格式大致都是(原or转) 二级目录 (标题) 2.因 ...

  3. GBDT(梯度提升树)scikit-klearn中的参数说明及简汇

    1.GBDT(梯度提升树)概述: GBDT是集成学习Boosting家族的成员,区别于Adaboosting.adaboosting是利用前一次迭代弱学习器的误差率来更新训练集的权重,在对更新权重后的 ...

  4. EasyUi DataGrid 请求Url两次问题

    easyui datagrid 1.4 当total为0时,请求两次url问题 框架问题:需要在easyui文件后加修补补丁 /** * The Patch for jQuery EasyUI 1.4 ...

  5. Spring 笔记(一)概念梳理

    概念 预备知识 1. POJO POJO是Plain Old Java Object的缩写,是软件开发大师Martin Fowler提出的一个概念,指的是一个普通Java类.也就说,你随便编写一个Ja ...

  6. Swift中由找不到removeAll(where:)方法引起的连锁反应(上)

    核心代码 section.removeAll {baseRow in if let habitRow = baseRow as? HabitRow{ let idxPath = habitRow.in ...

  7. BZOJ1079 [SCOI2008]着色方案 【dp记忆化搜索】

    题目 有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块. 所有油漆刚好足够涂满所有木块,即c1+c2+-+ck=n.相邻两个木块涂相同色显得很难看 ...

  8. 刷题总结——子串(NOIP2015)

    题目: 题目背景 NOIP2015 提高组 Day2 T2 题目描述 有两个仅包含小写英文字母的字符串 A 和 B .现在要从字符串 A 中取出 k 个互不重叠的非空子串,然后把这 k 个子串按照其在 ...

  9. HDU 1159 最长公共子序列(n*m)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  10. JS实现 java的Map

    Map = function () { this.objects = new Object(); // 加入元素 this.put = function (key, value) { this.obj ...