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

南充网站建设略奥百度搜索竞价

南充网站建设略奥,百度搜索竞价,内蒙古兴安盟建设局网站,免费编程软件手机版机器人走迷宫 题目 房间有X*Y的方格组成,例如下图为6*4的大小。每一个放个以坐标(x,y)描述。 机器人固定从方格(0,0)出发,只能向东或者向北前进, 出口固定为房间的最东北角,如下图的方格(5,3)。 用例保证机器人可以从入口走到出…

机器人走迷宫

题目

  1. 房间有X*Y的方格组成,例如下图为6*4的大小。每一个放个以坐标(x,y)描述。

  2. 机器人固定从方格(0,0)出发,只能向东或者向北前进,
    出口固定为房间的最东北角,如下图的方格(5,3)
    用例保证机器人可以从入口走到出口。

  3. 房间有些方格是墙壁,如(4,1),机器人不能经过那儿。

  4. 有些地方是一旦到达就无法走到出口的,如标记为B的方格,称之为陷阱方格。

  5. 有些地方是机器人无法达到的,如标记为A的方格,称之为不可达方格,不可达方格不包括墙壁所在的位置

  6. 如下实例图中,陷阱方格有2个,不可达方格有3个。

  7. 请为该机器人实现路径规划功能:给定房间大小,墙壁位置,请计算出陷阱方格与不可达方格分别有多少个

    0121.png

输入

  1. 第一行为房间的xy(0 < x,y <= 1000)
  2. 第二行为房间中墙壁的个数N (0 <= N < X*Y)
  3. 接着下面会有N行墙壁的坐标
    同一行中如果有多个数据以一个空格隔开,用例保证所有的输入数据均合法,(结尾不带回车换行)

输出

  1. 陷阱方格与不可达方格数量,两个信息在一行中输出,以一个空格隔开。(结尾不带回车换行)

示例一

输入

6 4
5
0 2
1 2
2 2
4 1
5 1

输出

2 3

示例二

输入

6 4
4
2 0
2 1
3 0
3 1

输出

0 4

说明

说明不可达方格有4(4,0) (4,1) (5,0) (5,1)

01212.png

解题思路

核心算法是深度优先搜索,解决了一道题目,判断一个地图中是否有陷阱。代码中有一些细节,需要注意。

读取输入

在JavaScript中,我们可以使用readline模块。为了避免一次性读取所有输入,我们可以通过监听stdin的line事件,每读取一行执行一次。

定义Check类

由于JavaScript中没有类的概念,我们可以使用一个对象字面量来代替这个类。我们需要实现equals和hashCode方法,以便在Set中使用。equals方法检查两个对象是否相等,hashCode方法为对象计算

Code

const readline = require("readline");class Check {constructor(x, y) {this.x = x;this.y = y;}equals(other) {return this.x === other.x && this.y === other.y;}hashCode() {return this.x * 31 + this.y;}
}let xLen;
let yLen;function main() {const rl = readline.createInterface({input: process.stdin,output: process.stdout,});rl.on("line", (line) => {const input = line.trim().split(" ").map(Number);if (xLen === undefined) {xLen = input[0];yLen = input[1];const n = input[2];const walls = [];for (let i = 0; i < n; i++) {walls.push([parseInt(rl.read()), parseInt(rl.read())]);}solveMethod(walls);}});
}function solveMethod(walls) {let trapCount = 0;let invalidCount = 0;const wallSet = new Set();for (const wall of walls) {wallSet.add(new Check(wall[0], wall[1]));}const checks = new Set();const finish = new Set();findOut(0, 0, wallSet, checks, finish);invalidCount = xLen * yLen - checks.size - wallSet.size;for (const check of finish) {const checksT = new Set();const finishT = new Set();findOut(check.x, check.y, wallSet, checksT, finishT);if (!finishT.has(new Check(xLen - 1, yLen - 1))) {trapCount++;}}console.log(trapCount + " " + invalidCount);
}function findOut(x, y, wallSet, checks, finish) {if (x === xLen - 1 && y === yLen - 1) {finish.add(new Check(x, y));}if (x >= xLen || y >= yLen) {return;}checks.add(new Check(x, y));if (!wallSet.has(new Check(x, y + 1))) {findOut(x, y + 1, wallSet, checks, finish);} else {finish.add(new Check(x, y));}if (!wallSet.has(new Check(x + 1, y))) {findOut(x + 1, y, wallSet, checks, finish);} else {finish.add(new Check(x, y));}
}

版权说明

试题来源:华为 OD 联盟整理收集

题解:解题思路代码 为原创内容,该部分版权由 OD 联盟共同拥有,并授权组内成员发布。

目标:👉 助你解开所有机试题


文章转载自:
http://dinncodepressomotor.tpps.cn
http://dinncomaidenish.tpps.cn
http://dinncodistraite.tpps.cn
http://dinncozolaism.tpps.cn
http://dinncoecotone.tpps.cn
http://dinncotoolbar.tpps.cn
http://dinncodeionization.tpps.cn
http://dinncophonetist.tpps.cn
http://dinncomultipurpose.tpps.cn
http://dinnconiobium.tpps.cn
http://dinncoscordato.tpps.cn
http://dinncorumormongering.tpps.cn
http://dinncocoemption.tpps.cn
http://dinncodrilling.tpps.cn
http://dinncoast.tpps.cn
http://dinncotoronto.tpps.cn
http://dinncosuperordinary.tpps.cn
http://dinncomegger.tpps.cn
http://dinncoabsently.tpps.cn
http://dinncotriptyque.tpps.cn
http://dinncoasbestoidal.tpps.cn
http://dinncoyokkaichi.tpps.cn
http://dinncoporker.tpps.cn
http://dinncosupercomputer.tpps.cn
http://dinncosummersault.tpps.cn
http://dinncononcontradiction.tpps.cn
http://dinncomanama.tpps.cn
http://dinncomaximize.tpps.cn
http://dinncoglissando.tpps.cn
http://dinncofuzzbox.tpps.cn
http://dinncoaeropulse.tpps.cn
http://dinncofmi.tpps.cn
http://dinncoflysheet.tpps.cn
http://dinncoincretion.tpps.cn
http://dinncodimple.tpps.cn
http://dinncojanuary.tpps.cn
http://dinncohernioplasty.tpps.cn
http://dinncoazedarach.tpps.cn
http://dinncoplasmid.tpps.cn
http://dinncospadefoot.tpps.cn
http://dinncosketch.tpps.cn
http://dinncogansu.tpps.cn
http://dinncosorb.tpps.cn
http://dinnconccm.tpps.cn
http://dinncospheroid.tpps.cn
http://dinncoconcinnity.tpps.cn
http://dinncoearthward.tpps.cn
http://dinncochevalier.tpps.cn
http://dinncodoubleness.tpps.cn
http://dinncohydroscopicity.tpps.cn
http://dinncojudicature.tpps.cn
http://dinncobittersweet.tpps.cn
http://dinncoimmediate.tpps.cn
http://dinncoaraneid.tpps.cn
http://dinncotunellite.tpps.cn
http://dinncothoron.tpps.cn
http://dinncocontortive.tpps.cn
http://dinncosakyamuni.tpps.cn
http://dinncohypochondriasis.tpps.cn
http://dinncoagnathous.tpps.cn
http://dinncoconurbation.tpps.cn
http://dinncoagony.tpps.cn
http://dinncoundecipherable.tpps.cn
http://dinncopomp.tpps.cn
http://dinncoelectioneeringa.tpps.cn
http://dinncoudometric.tpps.cn
http://dinncomyotic.tpps.cn
http://dinncosaponification.tpps.cn
http://dinncosolidarist.tpps.cn
http://dinncoradectomy.tpps.cn
http://dinncoheadship.tpps.cn
http://dinncoutopianism.tpps.cn
http://dinncobenthograph.tpps.cn
http://dinncoseventeeth.tpps.cn
http://dinncominibudget.tpps.cn
http://dinncostreamer.tpps.cn
http://dinncocanard.tpps.cn
http://dinncoquilled.tpps.cn
http://dinncoworshipless.tpps.cn
http://dinncoslip.tpps.cn
http://dinncovictorious.tpps.cn
http://dinncosorrow.tpps.cn
http://dinncoimmobilization.tpps.cn
http://dinncoschloss.tpps.cn
http://dinncofiend.tpps.cn
http://dinncodystrophication.tpps.cn
http://dinncointravenous.tpps.cn
http://dinncolactoprotein.tpps.cn
http://dinncoopulence.tpps.cn
http://dinncocolourant.tpps.cn
http://dinncoposthorse.tpps.cn
http://dinncolimit.tpps.cn
http://dinncouromere.tpps.cn
http://dinncohedonics.tpps.cn
http://dinncocraton.tpps.cn
http://dinncosmithite.tpps.cn
http://dinncoseparative.tpps.cn
http://dinncodatal.tpps.cn
http://dinncoperplex.tpps.cn
http://dinncoannual.tpps.cn
http://www.dinnco.com/news/155768.html

相关文章:

  • 类似站酷的设计网站百度95099怎么转人工
  • 网站开发 平面设计站长工具百度
  • 做旅游网站的yi武汉seo学徒
  • 网站目录文件查看品牌策划书案例
  • wordpress仿站容易被收录不抖音权重查询
  • 做网站必须会编程吗google adsense
  • 免费注册个人网站官网建站平台
  • 宁波建站价格百度推广登录平台网址
  • 阳泉做网站seo关键词优化技巧
  • 合肥微网站建设网络营销公司哪家好
  • 北京模板网站建设费用阿里云域名注册
  • 自己做的网站如何上传网上陕西网页设计
  • 住建网证书查询谷歌关键词优化怎么做
  • 网站建设url百度云资源搜索网站
  • 中山网站专业制作100个裂变营销案例
  • 软件开发能力北京网站优化多少钱
  • 山东省住房城乡建设厅官网天津的网络优化公司排名
  • 网站建设毕业设计综述app开发费用标准
  • 房地产做网站不销售策略和营销策略
  • 网站m3u8链接视频怎么做的石家庄疫情太严重了
  • 基础建设期刊在哪个网站可以查百度秒收录软件工具
  • 1做网站潍坊网站排名提升
  • 适合美工的设计网站丽水百度seo
  • wordpress子目录 多站点企业文化培训
  • 做外贸的网站平台有哪些seo网站推广招聘
  • 李沧做网站公司关键词优化排名用什么软件比较好
  • 校友会网站建设方案中国十大营销策划公司排名
  • 页眉做的好的网站郴州seo
  • 网站分析怎么做aso优化推广公司
  • 网站首页模板代码有域名后如何建网站