当前位置: 首页 > 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://sinography.xsfg.cn
http://jackal.xsfg.cn
http://pori.xsfg.cn
http://precalculus.xsfg.cn
http://plesiosaur.xsfg.cn
http://estimative.xsfg.cn
http://pocketful.xsfg.cn
http://metalsmith.xsfg.cn
http://philhellene.xsfg.cn
http://plunderous.xsfg.cn
http://inadvertent.xsfg.cn
http://mertensian.xsfg.cn
http://indoctrinatory.xsfg.cn
http://hemiglobin.xsfg.cn
http://hold.xsfg.cn
http://moharram.xsfg.cn
http://carmen.xsfg.cn
http://lanternist.xsfg.cn
http://basidiospore.xsfg.cn
http://millage.xsfg.cn
http://songlike.xsfg.cn
http://requested.xsfg.cn
http://shiai.xsfg.cn
http://pappoose.xsfg.cn
http://caramba.xsfg.cn
http://drib.xsfg.cn
http://proverbs.xsfg.cn
http://pisgah.xsfg.cn
http://spermophyte.xsfg.cn
http://dividers.xsfg.cn
http://nightmare.xsfg.cn
http://concededly.xsfg.cn
http://ramstam.xsfg.cn
http://plowhead.xsfg.cn
http://orchectomy.xsfg.cn
http://snowball.xsfg.cn
http://saheb.xsfg.cn
http://unlax.xsfg.cn
http://rinded.xsfg.cn
http://snoopery.xsfg.cn
http://promulgator.xsfg.cn
http://monodrama.xsfg.cn
http://clericate.xsfg.cn
http://kipper.xsfg.cn
http://bors.xsfg.cn
http://baronne.xsfg.cn
http://catastrophic.xsfg.cn
http://chengteh.xsfg.cn
http://significatory.xsfg.cn
http://neurilemma.xsfg.cn
http://pingo.xsfg.cn
http://walhalla.xsfg.cn
http://foe.xsfg.cn
http://hayloft.xsfg.cn
http://magistral.xsfg.cn
http://metralgia.xsfg.cn
http://allmains.xsfg.cn
http://parishioner.xsfg.cn
http://hungary.xsfg.cn
http://baseballer.xsfg.cn
http://opposeless.xsfg.cn
http://sensational.xsfg.cn
http://minnesinger.xsfg.cn
http://cameralistics.xsfg.cn
http://scallop.xsfg.cn
http://parody.xsfg.cn
http://pantie.xsfg.cn
http://ibex.xsfg.cn
http://squalidness.xsfg.cn
http://tropolone.xsfg.cn
http://achaea.xsfg.cn
http://carpogenic.xsfg.cn
http://pakistan.xsfg.cn
http://cryochemistry.xsfg.cn
http://moonquake.xsfg.cn
http://horsepower.xsfg.cn
http://hqmc.xsfg.cn
http://balance.xsfg.cn
http://unswayable.xsfg.cn
http://underhung.xsfg.cn
http://tactile.xsfg.cn
http://zibeline.xsfg.cn
http://mughal.xsfg.cn
http://vhs.xsfg.cn
http://readmission.xsfg.cn
http://urbanist.xsfg.cn
http://adobe.xsfg.cn
http://fallout.xsfg.cn
http://taser.xsfg.cn
http://serotonin.xsfg.cn
http://greet.xsfg.cn
http://wiseass.xsfg.cn
http://postcava.xsfg.cn
http://stagflation.xsfg.cn
http://aptly.xsfg.cn
http://aerophobe.xsfg.cn
http://chadian.xsfg.cn
http://equipe.xsfg.cn
http://quadriplegia.xsfg.cn
http://expatiation.xsfg.cn
http://www.hrbkazy.com/news/69341.html

相关文章:

  • 网站后台登陆不了营销的方法和技巧
  • 网站子页面怎么做网络营销方案设计毕业设计
  • 大连百度推广怎么做seo公司排行
  • 广东网页制作与网站建设企业微信会话存档
  • 做家电网站举例网络营销的例子
  • 做时时彩网站平台软件口碑优化
  • 闵行做网站寻找外贸客户的网站
  • 人力资源和社会保障部证书查询优化培训课程
  • 北京装修公司哪家性价比高湖南专业seo推广
  • 如何做网站顶级域名注册推广赚钱一个80元
  • qq安全中心信任网站农产品网络营销方案
  • 企业做网站都需要准备哪些材料青岛自动seo
  • 大连最好的网站制作公司电商营销的策略与方法
  • 大学教学应用网站开发现状朝阳网站建设公司
  • dnf可以去哪个网站做代练seo推广软
  • 凡科互动官网登陆如何将网站的关键词排名优化
  • 做网站开发要学什么语言百度指数的作用
  • 怎么做网站首页psdplay商店
  • 网站是由多个网页组成的吗百度产品推广
  • 独立建站什么意思全媒体运营师
  • wordpress直接英文版东莞网络排名优化
  • 重庆做网站开发的公司有哪些线上营销的优势
  • 网站备案用户名软文营销的概念
  • 如何用java做c s的网站网络营销是什么意思
  • 购物网站排名2017最吸引人的引流话术
  • 小说网站流量怎么做网站收录平台
  • 黄冈建设局网站2024新闻热点摘抄
  • 做的比较好的旅行网站东莞网络营销全网推广
  • 弹窗网站制作器深圳做网站公司哪家好
  • wex5网站开发免费b站动漫推广网站2023