题目连接: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. [转]ANDROID JNI之JAVA域与c域的互操作

    本文讲述AndroidJava域与C域互操作:Java域调用c域的函数:c域访问Java域的属性和方法:c域生成的对象的保存与使用.重点讲解c域如何访问Java域. 虽然AndroidJNI实现中,c ...

  2. linux 广播

    广播是一台主机向局域网内的所有主机发送数据.这时,同一网段的所有主机都能接收到数据.发送广播包的步骤大致如下: (1)确定一个发送广播的接口,如eth0 (2)确定广播的地址,通过ioctl函数,请求 ...

  3. Spring整合EhCache详解

    一.EhCache介绍 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider.Ehcache是一种广泛使用的开 源Java分布 ...

  4. selenium定位弹出菜单

    写selenium脚本,在浏览器定位各种弹出菜单时,有时用工具很难去取菜单的属性,下面说下如何去取: 点开firebug ,切换到“脚本”界面,首先在输入框输入单字母s,待弹出下拉列表后,单击左侧的插 ...

  5. PC Server远程管理卡用户管理脚本实现

    1.IPMI工作原理图: 2.脚本实现流程图: 3.适配服务器机型: 4.演示效果: 5.实现代码: #!/usr/bin/env bash # Author : JACK ZHAO # Date : ...

  6. CSU-2214 Sequence Magic

    题目链接 http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2214 题目 Description 有一个1到N的自然数序列1,2,3, ...

  7. ctags+cscope替换sourceinsight

    背景 windows环境开发+linux交叉编译的开发模式,代码阅读和编写都用的source-insight. 除了检索,跳转,工程构建等方面,sourceinsight自带了一些宏语言,可以轻松实现 ...

  8. 课时1:我和python的第一次亲密接触

    目录: 一.Python3的下载与安装 二.从IDIE启动Python 三.尝试点新的东西 四.为什么会这样? 五.课时01课后习题及答案 ============================== ...

  9. Qt(1)

    Qt Qt开发图形界面软件,可以跨win.linux.mac平台.移动端,使用c++开发 Qt采用所见即所得的UI设计(UI设计和代码是联动的),GUI界面编辑信号和槽,由开发环境自动生成c++代码, ...

  10. DB2数据库的日志文件管理

    DB2数据库的日志文件管理 DB2的日志模式 1.1循环日志 当循环日志生效时,事务数据将通过循环的方式写入主要日志文件.当存储于某个日志文件中的所有记录都不再需要用于恢复时,该日志文件将被重用,并且 ...