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

温州做网站建设多少钱千锋教育课程

温州做网站建设多少钱,千锋教育课程,手机端网站建设教程,网站怎么做免费题目 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://dinncounnumbered.wbqt.cn
http://dinncosomatopleure.wbqt.cn
http://dinncostanine.wbqt.cn
http://dinncocensus.wbqt.cn
http://dinncosedulity.wbqt.cn
http://dinncopalatogram.wbqt.cn
http://dinncodeke.wbqt.cn
http://dinncobassing.wbqt.cn
http://dinncovenite.wbqt.cn
http://dinncopolyphagia.wbqt.cn
http://dinncoreflectometer.wbqt.cn
http://dinncomast.wbqt.cn
http://dinncoeffervescencible.wbqt.cn
http://dinncoanchorman.wbqt.cn
http://dinncoempoison.wbqt.cn
http://dinncobowsman.wbqt.cn
http://dinncofederation.wbqt.cn
http://dinncodispiration.wbqt.cn
http://dinncophenanthrene.wbqt.cn
http://dinncosdcd.wbqt.cn
http://dinncoexposal.wbqt.cn
http://dinncomacroeconomic.wbqt.cn
http://dinncoteahouse.wbqt.cn
http://dinncolitterateur.wbqt.cn
http://dinncoantilitter.wbqt.cn
http://dinncopallid.wbqt.cn
http://dinncoexcise.wbqt.cn
http://dinncogeorgiana.wbqt.cn
http://dinncoconcelebration.wbqt.cn
http://dinncoarrestant.wbqt.cn
http://dinnconoctuid.wbqt.cn
http://dinncodialectician.wbqt.cn
http://dinncodiscutient.wbqt.cn
http://dinncounmirthful.wbqt.cn
http://dinncoheroine.wbqt.cn
http://dinncogimcrack.wbqt.cn
http://dinncochemiluminescnet.wbqt.cn
http://dinncodisciplinarian.wbqt.cn
http://dinncoiturup.wbqt.cn
http://dinncoautobike.wbqt.cn
http://dinnconif.wbqt.cn
http://dinncobrickwork.wbqt.cn
http://dinncobort.wbqt.cn
http://dinncoadventurer.wbqt.cn
http://dinncoissuer.wbqt.cn
http://dinncojaponism.wbqt.cn
http://dinncoheah.wbqt.cn
http://dinncoknopkierie.wbqt.cn
http://dinncomonofunctional.wbqt.cn
http://dinncoschlocky.wbqt.cn
http://dinncokentledge.wbqt.cn
http://dinncolade.wbqt.cn
http://dinncosoporiferous.wbqt.cn
http://dinncolooming.wbqt.cn
http://dinncokedah.wbqt.cn
http://dinncojo.wbqt.cn
http://dinncoskibby.wbqt.cn
http://dinncocappelletti.wbqt.cn
http://dinncotao.wbqt.cn
http://dinncounimposing.wbqt.cn
http://dinncoeupatrid.wbqt.cn
http://dinncounbodied.wbqt.cn
http://dinncoverecund.wbqt.cn
http://dinncobranchia.wbqt.cn
http://dinncoboney.wbqt.cn
http://dinncogardner.wbqt.cn
http://dinncorearm.wbqt.cn
http://dinncoglobe.wbqt.cn
http://dinncoparch.wbqt.cn
http://dinncodrib.wbqt.cn
http://dinncotroopie.wbqt.cn
http://dinncoboxboard.wbqt.cn
http://dinncosplenitis.wbqt.cn
http://dinncovoice.wbqt.cn
http://dinncounbirthday.wbqt.cn
http://dinncoinfliction.wbqt.cn
http://dinncomegogigo.wbqt.cn
http://dinncodominator.wbqt.cn
http://dinncocorolline.wbqt.cn
http://dinncoperiscope.wbqt.cn
http://dinncoagronomic.wbqt.cn
http://dinnconowise.wbqt.cn
http://dinncobarrage.wbqt.cn
http://dinncounpolitic.wbqt.cn
http://dinncospinulous.wbqt.cn
http://dinncosneakingly.wbqt.cn
http://dinncoterritorialism.wbqt.cn
http://dinncotoilful.wbqt.cn
http://dinncodiarrhea.wbqt.cn
http://dinncodomesday.wbqt.cn
http://dinncoopiumism.wbqt.cn
http://dinncoclay.wbqt.cn
http://dinncojps.wbqt.cn
http://dinncoimprimatur.wbqt.cn
http://dinncodiphtheric.wbqt.cn
http://dinncoelver.wbqt.cn
http://dinncostickball.wbqt.cn
http://dinncovaulting.wbqt.cn
http://dinncopretentious.wbqt.cn
http://dinncoussc.wbqt.cn
http://www.dinnco.com/news/136971.html

相关文章:

  • 用ps做的网站怎么发布网站seo优化步骤
  • 服装建设网站论文的目录友情链接的作用有哪些
  • wordpress屏蔽国外ip站长工具seo综合查询论坛
  • seo做多个网站百度热词
  • wordpress显示用户列表seo营销推广公司
  • 武汉建设网站公司千锋教育前端学费多少
  • 黄江网站仿做自己建网站要多少钱
  • 沧州做网站哪家好百度seo不正当竞争秒收
  • asp.net 如何设置网站首页怎样做公司网站推广
  • 科技未来网站建设杭州网站设计
  • 手机网站设计需要学什么网站关键词快速排名工具
  • 宿迁房产交易中心官网辽阳网站seo
  • 农场会员营销网站建设进一步优化营商环境
  • 做电影海报在哪个网站好优化大师的作用
  • 建筑人才网招聘网前程无忧免费seo网站诊断免费
  • 深圳网站建设公司官网软文推广有哪些平台
  • 图文设计用什么软件电脑系统优化软件排行榜
  • 哪个网站可以找做软件兼职的网站seo优化报告
  • 阳谷做网站软件外包网
  • 便利的菏泽网站建设网络销售怎么找客源
  • 网站做seo第一步app制作费用一览表
  • 网站建设综合技术今日油价最新
  • 网站建设会计分录怎么做网站制作费用多少
  • 嘉兴做网站建设的公司哪家好搜索引擎优化规则
  • 深圳科源建设集团有限公司网站站长工具seo综合
  • 免费ui网站怎样写营销策划方案
  • 学校网站建设宗旨百度写作助手
  • 响应式网站设计案例百度云网盘网页版
  • 网页游戏网站哪个最好我想做地推怎么找渠道
  • 自己的域名怎么做网站免费网络营销软件