CodeForces 540C Ice Cave (BFS)
题意:给定 n * m的矩阵,让你并给定初始坐标和末坐标,你只能走'.',并且走过的'.'都会变成'X',然后问你能不能在末坐标是'X'的时候走进去。
析:这个题,在比赛时就是没做出来,其实是一个水题,但是我理解错了意思,让下面提示的第一组样例给搞乱。
思路应该是这样的,从开始坐标BFS末坐标,把经过的都标成'X',如果直到末坐标是'.',接着走,如果能直到末坐标是'X',就是可以,否则就是不可以。
代码如下:
#include <bits/stdc++.h> using namespace std;
typedef long long LL;
const int maxn = 500 + 5;
const int INF = 0x3f3f3f3f;
const int dr[] = {0, 0, 1, -1};
const int dc[] = {1, -1, 0, 0};
struct node{
int r, c;
node(int rr = 0, int cc = 0) : r(rr), c(cc) { }
};
int n, m;
char s[maxn][maxn];
int r2, c2; bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} bool bfs(int r, int c){
queue<node> q;
q.push(node(r, c));
s[r][c] = 'X';
while(!q.empty()){
node u = q.front(); q.pop();
for(int i = 0; i < 4; ++i){
int x = u.r + dr[i];
int y = u.c + dc[i];
if(x == r2 && y == c2 && s[x][y] == 'X') return true;
if(is_in(x, y) && s[x][y] == '.'){
s[x][y] = 'X';
q.push(node(x, y));
}
}
}
return false;
} int main(){
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i)
scanf("%s", s[i]);
int r1, c1;
cin >> r1 >> c1 >> r2 >> c2;
--r1, --r2, --c1, --c2;
if(bfs(r1, c1)) puts("YES");
else puts("NO"); return 0;
}
CodeForces 540C Ice Cave (BFS)的更多相关文章
- CodeForces - 540C Ice Cave —— BFS
题目链接:https://vjudge.net/contest/226823#problem/C You play a computer game. Your character stands on ...
- CodeForces 540C Ice Cave (BFS)
http://codeforces.com/problemset/problem/540/C Ice Cave Time Limit:2000MS Memory Limit:262 ...
- 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 ...
- DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...
- (简单广搜) Ice Cave -- codeforces -- 540C
http://codeforces.com/problemset/problem/540/C You play a computer game. Your character stands on so ...
- BFS学习 Codeforces 301_div.2_Ice Cave
C. Ice Cave time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces 301_div.2_Ice Cave(BFS走冰块)
Ice Cave Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Descripti ...
- CF#301 C:Ice Cave(简单BFS)
C:Ice Cave 有一个m*n的地图,里面包含'.'表示完整的冰块,'X'表示有裂痕的冰块,当游戏者到达完整的冰块时,这个位置的冰块会变成有裂痕的冰块,如果到达有裂痕的冰块时,游戏者会进入下一关 ...
- 「日常训练」Ice Cave(Codeforces Round 301 Div.2 C)
题意与分析(CodeForces 540C) 这题坑惨了我....我和一道经典的bfs题混淆了,这题比那题简单. 那题大概是这样的,一个冰塔,第一次踩某块会碎,第二次踩碎的会掉落.然后求可行解. 但是 ...
随机推荐
- centos7系统安装python3,pip3,django
首先去python官网下载python3的源码包,网址:https://www.python.org/ 或者直接wget下载 wget https://www.python.org/ftp/pytho ...
- 第三章 Istio基本介绍
3.1 Istio的核心组件及其功能 Istio总体分两部分:控制面和数据面. 数据面(sidecar):sidecar通过注入的方式和业务容器共存于一个pod,会劫持业务容器的流量,并接受控制面组件 ...
- 源码安装nginx
#!/bin/bash #安装nginx依赖 apt-get update apt-get install -y make apt-get install -y gcc apt-get install ...
- 关于SQLSERVER的全文目录跟全文索引的区别
很久没有写随笔了,本来之前想写一篇关于SQLSERVER全文索引的随笔,可惜没有时间,一直拖到现在才有时间写,不好意思让各位久等了~ 先介绍一下SQLSERVER中的存储类对象,哈哈,先介绍一下概念嘛 ...
- nginx与tomcat整合
nginx与tomcat整合 1. 在/usr/local/nginx/conf下面添加文件proxy.conf # cat /usr/local/nginx/confg/proxy.conf p ...
- DOM库及常用方法封装
节点 nodeType nodeName nodeValue 元素节点 1 大写的标签名 null 文本节点 3 #text 文本内容 注释节点 8 #comment 注释内容 document 9 ...
- 经典CNN模型计算量与内存需求分析
表1 CNN经典模型的内存,计算量和参数数量对比 AlexNet VGG16 Inception-v3 模型内存(MB) >200 >500 90-100 参数(百万) 60 138 23 ...
- Linux HDD information (SATA/SCSI/SAS/SSD)
举例一: [reistlin@reistlin.com ~]$ cat /proc/scsi/scsi | grep Model Vendor: ATA Model: OCZ-VERTEX2 3.5 ...
- 检测客户端系统-PHP
if(isset($_SERVER['HTTP_USER_AGENT'])) { $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); $clie ...
- vue表单验证--veevalidate使用教程
vue表单验证----vee-validate使用教程 官网:https://baianat.github.io/vee-validate/ 一.安装 npm install vee-validate ...