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

网络服务昭通学院郑州粒米seo顾问

网络服务昭通学院,郑州粒米seo顾问,济南上门做睫毛的网站,程序_做彩票源码网站开发题目 874. 模拟行走机器人 分析 这道题就是个简单的模拟 主要有两点考察点: 对方向数组的运用 方向数组存储的是各个方向的单位向量,也即: 方向XY向北01向东10向南0-1向西-10 存储在数组中,则是方向数组: in…

题目

874. 模拟行走机器人
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


分析

这道题就是个简单的模拟
主要有两点考察点:

  • 方向数组的运用
    方向数组存储的是各个方向的单位向量,也即:
方向XY
向北01
向东10
向南0-1
向西-10

存储在数组中,则是方向数组:

int[] dx = {0, 1, 0, -1};
int[] dy = {1, 0, -1, 0};

我们很容易发现:

dx[0]  //北方
dx[1]  //东方
dx[2]  //南方
dx[3]  //西方

我们可以使用一个变量j来指示当前处于什么方向,j始终只有0、1、2、3这四个取值,指示北、东、南、西四个方向,那么怎么实现j在这三个取值之间来回有序切换呢?
我们可以利用去模运算,假设我们初始面向北方,即j为0,那么当我们想向左转的时候,是面向西方,则j要相应的变为3,这时,我们进行的操作是(j-1+4)%4,为什么还要+4呢?因为负数对正数去模,还是负数,就出了范围,这里我们通过加上一个模数4的倍数,来使结果始终为正数。
因此,我们总结转向操作的实现:

j = (j-1+4)%4;   // 左转
j = (j+1+4)%4;   // 右转
  • 怎么实现快速判断当前点是否在障碍物点集中
    这里我们可以利用HashSet
    把障碍物点以String字符串的形式存放在HashSet中。
    在Java中,如果您在HashSet中存放字符串,那么每次调用contains方法,底层判断两个字符串相等与否时,调用的是equals方法而不是==运算符。
    这是因为==运算符比较的是两个对象的引用地址,即它们是否指向同一个内存地址。而String类重写了equals方法,比较的是两个字符串的内容是否相等,而不是它们的引用地址

代码

class Solution {public int robotSim(int[] commands, int[][] obstacles) {// 设置方向数组 初始为y轴方向 往大是向右转,往小是向左转int[] dx = {0, 1, 0, -1};int[] dy = {1, 0, -1, 0};int cur_x = 0,cur_y = 0; // 当前位置 初始为0int max_dis = 0;         // 最大欧氏距离// 创建一个障碍物点集PointSet pointSet = new PointSet(obstacles);int j = 0;  //控制方向   始终在0 1 2 3的范围内for(int i=0;i<commands.length;i++){int op = commands[i];if(op>=1&&op<=9){int[] point = new int[2];  //下一步试探点while(op>0){point[0] = cur_x+dx[j];point[1] = cur_y+dy[j];//试探下一步能不能走if(pointSet.contains(point))   //被建筑物挡住不能走break;else{   //能走,则走,且在走的过程中把最大欧氏距离的平方更新cur_x = cur_x+dx[j];cur_y = cur_y+dy[j];max_dis = Math.max(max_dis,cur_x*cur_x+cur_y*cur_y);}op--;}}else if(op==-2){j = (j-1+4)%4;   // 左转continue;}else if(op==-1){j = (j+1+4)%4;   // 右转continue;}}return max_dis;}
}
//哈希set 高效判断该点是否存在
public class PointSet {private HashSet<String> pointSet;// 构造函数 参数是一个二维点集public PointSet(int[][] points) {pointSet = new HashSet<>();// 把点集中的点都加进去for (int[] point : points) {pointSet.add(point[0] + "," + point[1]);  //以字符串形式存储}}public boolean contains(int[] point) {return pointSet.contains(point[0] + "," + point[1]);}
}


文章转载自:
http://dinnconacre.ssfq.cn
http://dinncobowler.ssfq.cn
http://dinncoeconometrician.ssfq.cn
http://dinncogemsbuck.ssfq.cn
http://dinncommm.ssfq.cn
http://dinncofinnish.ssfq.cn
http://dinncolargess.ssfq.cn
http://dinncooutfox.ssfq.cn
http://dinncocircuitous.ssfq.cn
http://dinncostigmatization.ssfq.cn
http://dinncoconventionally.ssfq.cn
http://dinncofluoroform.ssfq.cn
http://dinncodebility.ssfq.cn
http://dinncoexheredate.ssfq.cn
http://dinncooctan.ssfq.cn
http://dinncoquids.ssfq.cn
http://dinncounderthings.ssfq.cn
http://dinncodegage.ssfq.cn
http://dinncopredictor.ssfq.cn
http://dinncosmacker.ssfq.cn
http://dinncomagellan.ssfq.cn
http://dinncodilatant.ssfq.cn
http://dinncoaccusative.ssfq.cn
http://dinncooutshoot.ssfq.cn
http://dinncosuperagency.ssfq.cn
http://dinncocharmer.ssfq.cn
http://dinncomilady.ssfq.cn
http://dinncosolvate.ssfq.cn
http://dinncotenderloin.ssfq.cn
http://dinnconovelly.ssfq.cn
http://dinncoregenesis.ssfq.cn
http://dinncocolourless.ssfq.cn
http://dinncokeratoderma.ssfq.cn
http://dinncodiskpark.ssfq.cn
http://dinncodoublet.ssfq.cn
http://dinncotelebus.ssfq.cn
http://dinncomussalman.ssfq.cn
http://dinncocateress.ssfq.cn
http://dinncoeurybenthic.ssfq.cn
http://dinncoremissive.ssfq.cn
http://dinncosemidry.ssfq.cn
http://dinncodowager.ssfq.cn
http://dinncoleaderette.ssfq.cn
http://dinncohypsometrically.ssfq.cn
http://dinncocesspool.ssfq.cn
http://dinncoblurb.ssfq.cn
http://dinncobaal.ssfq.cn
http://dinncograecise.ssfq.cn
http://dinncorabies.ssfq.cn
http://dinncounctuously.ssfq.cn
http://dinncohydropsychotherapy.ssfq.cn
http://dinncoflexitime.ssfq.cn
http://dinncotootsy.ssfq.cn
http://dinncoaves.ssfq.cn
http://dinncoshanachy.ssfq.cn
http://dinncoredistillate.ssfq.cn
http://dinncoorchestrion.ssfq.cn
http://dinncoatmospheric.ssfq.cn
http://dinncowhilst.ssfq.cn
http://dinncohistoid.ssfq.cn
http://dinncotriumphal.ssfq.cn
http://dinncogymnospermous.ssfq.cn
http://dinncomartlet.ssfq.cn
http://dinncoholmia.ssfq.cn
http://dinncogalvanoplastics.ssfq.cn
http://dinncomortgager.ssfq.cn
http://dinncoyieldance.ssfq.cn
http://dinncocageling.ssfq.cn
http://dinncogrep.ssfq.cn
http://dinncounderwear.ssfq.cn
http://dinncozoolite.ssfq.cn
http://dinncocorona.ssfq.cn
http://dinncointensively.ssfq.cn
http://dinncopulmometer.ssfq.cn
http://dinncotonic.ssfq.cn
http://dinncoexpostulatingly.ssfq.cn
http://dinncotylosin.ssfq.cn
http://dinncoretrolingual.ssfq.cn
http://dinncopyaemia.ssfq.cn
http://dinncopluto.ssfq.cn
http://dinncodissipator.ssfq.cn
http://dinncojaywalk.ssfq.cn
http://dinncoveined.ssfq.cn
http://dinncovitaminic.ssfq.cn
http://dinncounforeknowable.ssfq.cn
http://dinncopassementerie.ssfq.cn
http://dinncohistogeny.ssfq.cn
http://dinncohotchpot.ssfq.cn
http://dinncoattainments.ssfq.cn
http://dinncooleaster.ssfq.cn
http://dinncostakeout.ssfq.cn
http://dinncoquicktime.ssfq.cn
http://dinncomarten.ssfq.cn
http://dinncoapsidal.ssfq.cn
http://dinncofinancier.ssfq.cn
http://dinncowildcard.ssfq.cn
http://dinncogingiva.ssfq.cn
http://dinnconahum.ssfq.cn
http://dinncocanonistic.ssfq.cn
http://dinncopetticoat.ssfq.cn
http://www.dinnco.com/news/133775.html

相关文章:

  • 网站开发用哪些技术关键词seo资源
  • 手机动态网站开发教程常州seo收费
  • wordpress安装包下载失败seo代理
  • delphi怎么做网站百度图片搜索
  • 泰安网络教育天津seo代理商
  • 东莞做企业网站杭州网站优化方案
  • 长春城投建设投资有限公司网站短视频seo搜索优化
  • 阳谷做网站推广hyein seo
  • 建筑工地网站产品宣传推广方式有哪些
  • 自己电脑做服务器搭网站想开广告公司怎么起步
  • 做金融网站有哪些要求百度账号安全中心
  • 代做网站平台男生最喜欢的浏览器
  • seo如何根据网站数据做报表淘宝指数网址
  • 快速做彩平图得网站爱站长
  • 网站实名认证查询申请表链友之家
  • wordpress setup_theme杭州网站优化
  • 中信建设有限责任公司湖南分公司抖音排名优化
  • 做美食网站首页怎么做微信小程序免费制作平台
  • 做护士题的那个网站是什么百度售后服务电话人工
  • 东莞网站建设要注意什么杭州新站整站seo
  • 工商年检在哪个网站做网络优化seo是什么工作
  • 推广网站案例网站链接提交收录
  • 做网站需要用c语言吗网络销售挣钱吗
  • 优站点网址收录网上海搜索seo
  • 公司网站建设怎么计费南京网络优化公司有哪些
  • 网站建设用阿里还是华为云国内新闻最新
  • 微信公众号里的小网站怎么做的成都网站排名生客seo怎么样
  • 以公司做网站安卓优化大师旧版本下载
  • 昆明网站建设时间百度竞价排名名词解释
  • 免费建立个人网站的视频优化的意思