Codeforces Round #301 (Div. 2) C. Ice Cave BFS

C. Ice Cave

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/540/problem/C

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

4 6
X...XX
...XX.
.X..X.
......
1 6
2 2

 

Sample Output

YES

 

HINT

In the first sample test one possible path is:

After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.

题意

有一个矩形区域,一开始你在一个地方,你只能走.的位置,走了之后.就会变成X,然后你必须让终点变成x,然后再走上去

问你可不可行

题解:

BFS搞一搞就好了,裸题= =

代码:

 

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
//const int inf=0x7fffffff;   //§ß§é§à§é¨f§³
const int inf=0x3f3f3f3f;
/*inline void P(int x)
{Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts("");
}
*/
inline ll read()
{int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
inline void P(int x)
{Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts("");
}
//**************************************************************************************string s[1000];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
struct node
{int x,y;int t;
};
int vis[1000][1000];
int main()
{int n=read(),m=read();for(int i=0;i<n;i++)cin>>s[i];node st,ed;cin>>st.x>>st.y;st.x--,st.y--;st.t=0;cin>>ed.x>>ed.y;ed.x--,ed.y--;queue<node> q;q.push(st);while(!q.empty()){node now=q.front();q.pop();for(int i=0;i<4;i++){node next=now;next.x+=dx[i];next.y+=dy[i];next.t++;if(next.x<0||next.x>=n||next.y<0||next.y>=m)continue;if(next.x==ed.x&&next.y==ed.y&&s[next.x][next.y]=='X'){printf("YES\n");return 0;}if(s[next.x][next.y]=='X')continue;q.push(next);s[next.x][next.y]='X';}}printf("NO\n");
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/460258.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

字符串匹配的KMP算法(转)

转自&#xff1a;http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html 字符串匹配是计算机的基本任务之一。 举例来说&#xff0c;有一个字符串"BBC ABCDAB ABCDABCDABDE"&#xff0c;我想知道&#xff0c;里面是否包含另一个…

java游戏运行环境_Java运行环境

一、计算机存储单元位(bit)&#xff1a; 一个数字0或者一个数字1&#xff0c;代表一位字节(Byte): 每逢8位是一个字节&#xff0c;计算机中数据存储的最小的单位1 Byte 8bit通常的换算单位&#xff1a;1KB1024B1MB1024KB1GB1024MB...二、java语言的跨平台性JVM: java虚拟机&…

logcat使用

做android有些日子了&#xff0c;只是对主要的logcat的具体使用方法还是非常模糊&#xff0c;今天有空&#xff0c;学习一下。 logcat能够在adb中使用&#xff0c;也能够直接在命令行下使用。 logcat [options] [filterspecs] logcat的选项包含: -s 默认…

BNUOJ 1207 滑雪

滑雪 Time Limit: 1000msMemory Limit: 65536KBThis problem will be judged on PKU. Original ID: 108864-bit integer IO format: %lld Java class name: MainMichael喜欢滑雪百这并不奇怪&#xff0c; 因为滑雪的确很刺激。可是为了获得速度&#xff0c;滑的区域必须向…

eclipse的java帮助文档_java在Eclipse中文apidoc帮助文档导入.doc

今天一下午都在整java的api。我的目标是在eclipse平台中用鼠标点击java的api就会自动显示出中文的注释。并且能在help中方便地搜索java的api。 这其实是使用bada开发平台后留下的后遗症。最终结果是没有得到满意答案&#xff0c;发现最方便的方法还是另外开一个chm中文api文档。…

1477: 青蛙的约会

1477: 青蛙的约会 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 261 Solved: 164[Submit][Status][Discuss]Description 两只青蛙在网上相识了&#xff0c;它们聊得很开心&#xff0c;于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上&#xff0c;于是它们…

altium designer 自动扇出功能

http://wenku.baidu.com/link?urlUJLUQWqm2KwzQzcWxhgsL-Xk4wcUBl-TIB0GAWVD9lC2jrDiRHin0cln-4fMiK1Ku934CvlB-tV7FGEcXzfQL6uC4M58TpnZYCPlbfA4XgW转载于:https://www.cnblogs.com/asulove/p/3836247.html

elasticsearch java_java Elasticsearch详细介绍及使用实例分析

集群健康检查取得健康状态GET /_cat/health?v返回&#xff1a;epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent1535248805 10:00:05 elasticsearch yellow 1 1 1 1 0 0 1 0 - 50…

zabbix2.2入门教程之编译安装(一)

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。zabbix能监视各种网络参数&#xff0c;保证服务器系统的安全运营&#xff1b;并提供柔软的通知机制以让系统管理员快速定位/解决存在的各种问题。测试环境&#xff1a;centos6.4zabbix2.2…

数学图形(1.35)Kappa curve

不知道这个曲线和那个运动品牌背靠背有什么关系.阿迪原先的商标是个三叶草,难道背靠背也是由数学图形来的? 以下是维基上的解释. In geometry, the kappa curve or Gutschovens curve is a two-dimensional algebraic curve resembling the Greek letter ϰ (kappa). The kapp…

MeasureSpec学习 - 转

2019独角兽企业重金招聘Python工程师标准>>> 在自定义View和ViewGroup的时候&#xff0c;我们经常会遇到int型的 MeasureSpec 来表示一个组件的大小&#xff0c;这个变量里面不仅有组件的尺寸大小&#xff0c;还有大小的模式。 这个大小的模式&#xff0c;有点难以理…

ffmpeg 截图 java_Java Web 中使用ffmpeg实现视频转码、视频截图

视频网站中提供的在线视频播放功能,播放的都是FLV格式的文件,它是Flash动画文件,可通过Flash制作的播放器来播放该文件.项目中用制作的player.swf播放器.多媒体视频处理工具FFmpeg有非常强大的功能包括视频采集功能、视频格式转换、视频抓图、给视频加水印等。ffmpeg视频采集功…

Modernizr使用指南

很久很久以前&#xff0c;我们总有要自己写代码检测&#xff0c;浏览器对某种特性的支持情况。比如&#xff1a;现在要写代码判断浏览器是否支持canvans&#xff0c;大致的代码如下&#xff1a; window.onload function () {if (isSupportCanvas()) {alert("support canv…

C#反射基础理解1(转)

反射提供了封装程序集、模块和类型的对象&#xff08;Type类型&#xff09; 可以使用反射动态的创建类型的实例&#xff0c;将类型绑定到现有对象&#xff0c;或从现有对象中获取类型&#xff0c;然后&#xff0c;可以调用类型的方法或访问其字段和属性 。 总之&#xff0c;有了…

java sql超过32k_db2 clob类型如何能存储大于32k的字符串

#include #include int ascii[256]; // 字符出现次数,一共只有256个ascii码int main(){int i,r,j;char str[1024];printf("输入字符串\n");for (i 0; i < 256; i )ascii[i] 0; // 清零scanf("%s",str);r strlen(str);for (i 0; i < r; i ){ascii…

架​设​W​e​b​服​务​器

服务器是网站的灵魂&#xff0c;是打开网站的必要载体。按照体系架构来区分&#xff0c;服务器主要分为非X86服务器、x86服务器。非X86服务器使用RISC(精简指令集)或EPIC&#xff08;并行指令代码&#xff09;处理器&#xff1b;X86服务器又称CISC&#xff08;复杂指令&#xf…

在Linux和Mac OS X系统上运行.NET

.NET Core运行时已经看到了实现真正的跨平台的美好前景&#xff0c;它最终出现在Linux和Mac OS X平台上。在上周举办的Microsoft Build大会上&#xff0c;来自微软的项目经理Habib Heydarian为听众分析了这一举措对开发者们所带来的益处&#xff0c;并告诉开发者们如何开始探索…

java 不可修改的map_Java中如何实现不可变Map详解

前言有时最好不允许修改 java.util.Map&#xff0c; 例如跨线程共享只读数据。为此&#xff0c;我们可以使用Unmodifiable Map或Immutable Map。在这个快速教程中&#xff0c;我们将看到它们之间的区别。然后&#xff0c;我们将介绍可以创建不可变Map的各种方法。下面话不多说…

《.NET最佳实践》与Ext JS/Touch的团队开发

概述持续集成编码规范测试小结概述 有不少开发人员都问过我&#xff0c;Ext JS/Touch是否支持团队开发&#xff1f;对于这个问题&#xff0c;我可以毫不犹豫的回答&#xff1a;支持。原因是在Sencha官网博客中客户示例中&#xff0c;有不少项目都是基于团队模式开发的。 那为什…

Cocos2d-x 3.2 学习笔记(四)学习打包Android平台APK!

从cocos2dx 3.2项目打包成apk安卓应用文件&#xff0c;搭建安卓环境的步骤有点繁琐&#xff0c;但搭建一次之后&#xff0c;以后就会非常快捷&#xff01; &#xff08;涉及到3.1.1版本的&#xff0c;请自动对应3.2版本&#xff0c;3.x版本的环境搭建都是一样的&#xff09; 一…