当前位置: 首页 > news >正文

良品铺子网站建设目标电商软文范例

良品铺子网站建设目标,电商软文范例,成都 网站建设培训学校,梧州网站开发1112. 迷宫 - AcWing题库 一天Extense在森林里探险的时候不小心走入了一个迷宫,迷宫可以看成是由 n∗n 的格点组成,每个格点只有2种状态,.和#,前者表示可以通行后者表示不能通行。 同时当Extense处在某个格点时,他只…

1112. 迷宫 - AcWing题库

一天Extense在森林里探险的时候不小心走入了一个迷宫,迷宫可以看成是由 n∗n 的格点组成,每个格点只有2种状态,.#,前者表示可以通行后者表示不能通行。

同时当Extense处在某个格点时,他只能移动到东南西北(或者说上下左右)四个方向之一的相邻格点上,Extense想要从点A走到点B,问在不走出迷宫的情况下能不能办到。

如果起点或者终点有一个不能通行(为#),则看成无法办到。

注意:A、B不一定是两个不同的点。

输入格式

第1行是测试数据的组数 k,后面跟着 k 组输入。

每组测试数据的第1行是一个正整数 n,表示迷宫的规模是 n∗n 的。

接下来是一个 n∗n 的矩阵,矩阵中的元素为.或者#

再接下来一行是 4 个整数 ha,la,hb,lb,描述 A 处在第 ha 行, 第 la 列,B 处在第 hb 行, 第 lb 列。

注意到 ha,la,hb,lb 全部是从 0 开始计数的。

输出格式

k行,每行输出对应一个输入。

能办到则输出“YES”,否则输出“NO”。

数据范围

1≤n≤100

输入样例:
2
3
.##
..#
#..
0 0 2 2
5
.....
###.#
..#..
###..
...#.
0 0 4 0
输出样例:
YES
NO

解析 :

使用dfs进行判断代码要比bfs简洁

dfs代码:

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<math.h>
#include<map>
#include<sstream>
#include<deque>
#include<unordered_map>
using namespace std;
typedef long long LL;
const int N = 1e2 + 2;
int n, ha, la, hb, lb;
char str[N][N];
bool vis[N][N];
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
bool dfs(int x, int y) {if (str[x][y] == '#')return false;if (x == hb && y == lb)return true;for (int i = 0; i < 4; i++) {int a = x + dx[i], b = y + dy[i];if (a < 0 || a >= n || b < 0 || b >= n)continue;if (vis[a][b])continue;vis[a][b] = 1;if (dfs(a, b))return true;}return false;
}int main() {int T;cin >> T;while (T--) {cin >> n;for (int i = 0; i < n; i++) {scanf("%s", str[i]);}cin >> ha >> la >> hb >> lb;memset(vis, 0, sizeof vis);if (dfs(ha, la))cout << "YES" << endl;else cout << "NO" << endl;}return 0;
}

BFS代码:

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<math.h>
#include<map>
#include<sstream>
#include<deque>
#include<unordered_map>
using namespace std;
typedef long long LL;
const int N = 1e2 + 2;
int n,ha,la,hb,lb;
char str[N][N];
typedef pair<int, int> PII;
bool vis[N][N];string bfs() {string ret1 = "YES", ret2 = "NO";if (str[ha][la] == '#' || str[hb][lb] == '#')return ret2;int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };memset(vis, 0, sizeof vis);queue<PII>q;q.push({ ha,la });vis[ha][la] = 1;while (!q.empty()) {auto t = q.front();q.pop();if (t.first == hb && t.second == lb)return ret1;for (int i = 0; i < 4; i++) {int a = t.first + dx[i], b = t.second + dy[i];if (a < 0 || a >= n || b < 0 || b >= n)continue;if (str[a][b] == '#'||vis[a][b])continue;vis[a][b] = 1;q.push({ a,b });}}return ret2;
}int main() {int T;cin >> T;while (T--) {cin >> n;for (int i = 0; i < n; i++) {scanf("%s", str[i]);}cin >> ha >> la >> hb >> lb;cout << bfs() << endl;}return 0;
}

http://www.tj-hxxt.cn/news/82590.html

相关文章:

  • 摄影网站设计实现步骤免费的seo优化
  • 网上购物商城有哪些seo常用工具网站
  • 广东网站开发公司电话今日国际军事新闻
  • 钱宝网站怎么做任务桂林网站优化
  • 商城网站建设策划成都排名推广
  • 南京触屏网站开发营销型网站定制
  • 怎样做百度网站教育培训机构官网
  • 网站核检单搜索网站关键词
  • java做动态网站免费大数据查询平台
  • 没学过计算机开始学做网站抖音运营推广策划方案
  • b2b是什么意思啊微信seo什么意思
  • 百度广告联盟推广链接宣城网站seo
  • 班级网站建设思路北京疫情又严重了
  • 官方网站查询电工证郑州百度快照优化
  • 国外效果做的好的网站中国seo第一人
  • 2018做网站开发一个月工资多少网站的优化从哪里进行
  • 做消费信贷网站爱站网爱情电影网
  • 网站运营每天做的怎样加入网络营销公司
  • 微信个人号管理系统seo网站内容优化
  • 怎样网站制作设计此网站服务器不在国内维护
  • 彩票网站有人做吗app推广渠道在哪接的单子
  • 有哪些效果图做的好的网站网络推广发展
  • 怎样做网站认证seo免费外链工具
  • 怎样申请网站域名广告开户
  • 设计素材网站能挣钱吗短视频seo系统
  • 企业门户网站中国燃气河南推广网站
  • 地产网站建设方案常州网站建设书生商友
  • 山西网站制作公司哪家好湖南正规seo公司
  • html5网站带后台关键词排名优化易下拉霸屏
  • 原创wordpress付费主题搜索引擎排名优化方案