codeforces-540C
题目连接:http://codeforces.com/problemset/problem/540/C
2 seconds
256 megabytes
standard input
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?
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.
If you can reach the destination, print 'YES', otherwise print 'NO'.
4 6X...XX...XX..X..X.......1 62 2
YES
5 4.X.....XX.X......XX.5 31 1
NO
4 7..X.XX..XX..X.X...X..X......2 21 6
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的更多相关文章
- CodeForces 540C Ice Cave (BFS)
http://codeforces.com/problemset/problem/540/C Ice Cave Time Limit:2000MS Memory Limit:262 ...
- (简单广搜) Ice Cave -- codeforces -- 540C
http://codeforces.com/problemset/problem/540/C You play a computer game. Your character stands on so ...
- CodeForces 540C Program D
Description You play a computer game. Your character stands on some level of a multilevel ice cave. ...
- CodeForces 540C Ice Cave (BFS)
题意:给定 n * m的矩阵,让你并给定初始坐标和末坐标,你只能走'.',并且走过的'.'都会变成'X',然后问你能不能在末坐标是'X'的时候走进去. 析:这个题,在比赛时就是没做出来,其实是一个水题 ...
- CodeForces - 540C Ice Cave —— BFS
题目链接:https://vjudge.net/contest/226823#problem/C You play a computer game. Your character stands on ...
- 「日常训练」Ice Cave(Codeforces Round 301 Div.2 C)
题意与分析(CodeForces 540C) 这题坑惨了我....我和一道经典的bfs题混淆了,这题比那题简单. 那题大概是这样的,一个冰塔,第一次踩某块会碎,第二次踩碎的会掉落.然后求可行解. 但是 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
随机推荐
- Java基础-7数组
一).什么是数组: 数组是一组具有相同类型和名称的变量集合,把一系列相同类型的数据保存在一起,这些变量称为数组的元素:每个元素都有一个编号,这个编号叫做下标,下标从 0 开始:元素的个数被称为数组的长 ...
- PC Server远程管理卡用户管理脚本实现
1.IPMI工作原理图: 2.脚本实现流程图: 3.适配服务器机型: 4.演示效果: 5.实现代码: #!/usr/bin/env bash # Author : JACK ZHAO # Date : ...
- 数据结构与算法之顺序表C语言实现
顺序表等相关概念请自行查阅资料,这里主要是实现. 注: 1.顺序表C语言实现: 2.按较简单的方式实现,主要帮助理解,可在此基础上修改,更加完善: 3.提供几个简单函数,可自行添加功能: 4.可用C+ ...
- STL之map&multimap使用简介
map 1.insert 第一种:用insert函数插入pair数据 #include <map> #include <string> #include <iostrea ...
- python完成留言板功能
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="utf-8&quo ...
- hadoop +streaming 排序总结
参考http://blog.csdn.net/baidu_zhongce/article/details/49210787 hadoop用于对key的排序和分桶的设置选项比较多,在公司中主要以KeyF ...
- 解决:spring security 登录页停留时间过长 跳转至 403页面
前言:最近的项目中用到了spring security组件,说句显low的话:我刚开始都不知道用了security好不勒,提了bug,在改的过程中,遇到了一些问题,找同事交流,才知道是用的securi ...
- over窗口函数进阶
over窗口函数的其他灵活的用法.即,统计当前行的前N行及后N行数据.转自:https://blog.csdn.net/ck3207/article/details/84954511 先来看一下数据的 ...
- jQuery中Ajax的属性设置
1.全局设置为同步 $.ajaxSetup({ async: false });
- JAVA本地文本读取---解决中文乱码
import java.io.*; public class ReadFile { public static void main(String[] args) { try { File file = ...