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

网络营销专业就业方向seo研究中心vip课程

网络营销专业就业方向,seo研究中心vip课程,日本做a图片视频在线观看网站,商丘购物网站开发设计到家的最少跳跃次数【LC1654】 有一只跳蚤的家在数轴上的位置 x 处。请你帮助它从位置 0 出发,到达它的家。 跳蚤跳跃的规则如下: 它可以 往前 跳恰好 a 个位置(即往右跳)。它可以 往后 跳恰好 b 个位置(即往左跳&…

到家的最少跳跃次数【LC1654】

有一只跳蚤的家在数轴上的位置 x 处。请你帮助它从位置 0 出发,到达它的家。

跳蚤跳跃的规则如下:

  • 它可以 往前 跳恰好 a 个位置(即往右跳)。
  • 它可以 往后 跳恰好 b 个位置(即往左跳)。
  • 它不能 连续 往后跳 2 次。
  • 它不能跳到任何 forbidden 数组中的位置。

跳蚤可以往前跳 超过 它的家的位置,但是它 不能跳到负整数 的位置。

给你一个整数数组 forbidden ,其中 forbidden[i] 是跳蚤不能跳到的位置,同时给你整数 abx ,请你返回跳蚤到家的最少跳跃次数。如果没有恰好到达 x 的可行方案,请你返回 -1

  • 思路:最短路问题,BFS

    • **BFS:**寻找最少跳跃次数,所以可以使用最短路径Dijkstra 算法,通过BFS实现,队列元素需要存储当前跳跃次数以及当前位置;

    • **记录状态:**由于跳跃时连续向前次数不受限制,但是不能连续向后跳两次,因此跳跃时还需要记录前一跳跃的状态为向后还是向前;

      • 如果前一状态为向前,那么本次可以向前也可以向后
      • 如果前一状态为向后,那么本次只可以向前
    • 判断是否可以访问:

      • 首先判断最远右边界,由于向前跳跃次数不受限制,避免超时,需要寻找最远右边界【重点】
      • 当前位置不在forbidden数组中
      • 之前没有访问过该状态【位置+方向】
    • 寻找最远右边界:

      • 如果 a ≥ b a\ge b ab,那么最远右边界为 x + b x+b x+b,在大于 x + b x+b x+b的位置不可能到达 x x x

      • 如果 a < b a\lt b a<b,那么可以先向前跳再向后跳逐步接近目标位置 x x x,最远右边界为 m a x ( f + a + b , x ) max(f+a+b, x) max(f+a+b,x),其中 f f f m a x ( f o r b i d d e n ) max(forbidden) max(forbidden)证明略。

        感性认知:对于任何一条路径,若它包含了超过 m a x ( f + a + b , x ) max(f+a+b, x) max(f+a+b,x)的点,总能通过变换找到所有点都在 m a x ( f + a + b , x ) max(f+a+b, x) max(f+a+b,x)内的路径,且这条路径与原路径跳跃次数相同,对于该问题,这两条路径是等价的,所以只需考虑 m a x ( f + a + b , x ) max(f+a+b,x) max(f+a+b,x)内的路径即可

  • 实现

    class Solution {public int minimumJumps(int[] forbidden, int a, int b, int x) {Set<Integer> vis = new HashSet<>();Deque<int[]> pq = new LinkedList<>();// 跳跃次数、当前位置、连续向后跳次数int max = 0;       for (int f : forbidden){vis.add(f);max = Math.max(max, f);}      if (a > b){max = x + b;}else{max = Math.max(max + a + b, x);}boolean[][] flag = new boolean[max + 1][2];// 向前 向后一次flag[0][0] = true;pq.addLast(new int[]{0, 0, 0});while (!pq.isEmpty()){int[] node = pq.pollFirst();if (node[1] == x) return node[0]; // 向前int forward = node[1] + a;if (forward <= max && !vis.contains(forward) && !flag[forward][0]){flag[forward][0] = true;pq.addLast(new int[]{node[0] + 1, forward, 0});}// 向后int backward = node[1] - b;if (node[2] != 1 && backward >= 0 && !vis.contains(backward) && !flag[backward][1]){flag[backward][1] = true;pq.addLast(new int[]{node[0] + 1, backward, 1});}}return -1;}
    }
    


文章转载自:
http://freckling.bbrf.cn
http://delirifacient.bbrf.cn
http://airwash.bbrf.cn
http://munificent.bbrf.cn
http://maugre.bbrf.cn
http://compline.bbrf.cn
http://ultrastable.bbrf.cn
http://greenbelt.bbrf.cn
http://affiliate.bbrf.cn
http://normalization.bbrf.cn
http://disciform.bbrf.cn
http://alcoholism.bbrf.cn
http://jacobean.bbrf.cn
http://botanic.bbrf.cn
http://acyloin.bbrf.cn
http://blur.bbrf.cn
http://tetradymite.bbrf.cn
http://handwrite.bbrf.cn
http://regenerator.bbrf.cn
http://mishmi.bbrf.cn
http://tungstate.bbrf.cn
http://bleb.bbrf.cn
http://scallion.bbrf.cn
http://nevada.bbrf.cn
http://difficulty.bbrf.cn
http://sundeck.bbrf.cn
http://influencing.bbrf.cn
http://facemaking.bbrf.cn
http://scalloping.bbrf.cn
http://kiribati.bbrf.cn
http://matchbyte.bbrf.cn
http://mercurial.bbrf.cn
http://offer.bbrf.cn
http://cabomba.bbrf.cn
http://vasoconstrictor.bbrf.cn
http://regardless.bbrf.cn
http://doorstop.bbrf.cn
http://scleritis.bbrf.cn
http://polyoma.bbrf.cn
http://yawn.bbrf.cn
http://evangelistic.bbrf.cn
http://stumour.bbrf.cn
http://cither.bbrf.cn
http://guardrail.bbrf.cn
http://gaoleress.bbrf.cn
http://gauffer.bbrf.cn
http://detectivism.bbrf.cn
http://lacquerer.bbrf.cn
http://stroboscope.bbrf.cn
http://afeard.bbrf.cn
http://clinton.bbrf.cn
http://universalism.bbrf.cn
http://cacogastric.bbrf.cn
http://izar.bbrf.cn
http://congealer.bbrf.cn
http://telephotometer.bbrf.cn
http://irreparably.bbrf.cn
http://sniff.bbrf.cn
http://panelist.bbrf.cn
http://gaullist.bbrf.cn
http://vivisect.bbrf.cn
http://tiro.bbrf.cn
http://tempermament.bbrf.cn
http://artesian.bbrf.cn
http://bagnio.bbrf.cn
http://abridged.bbrf.cn
http://granadilla.bbrf.cn
http://aeriform.bbrf.cn
http://edemata.bbrf.cn
http://alpenhorn.bbrf.cn
http://trackman.bbrf.cn
http://reflux.bbrf.cn
http://unwieldy.bbrf.cn
http://skyward.bbrf.cn
http://operatic.bbrf.cn
http://semivolcanic.bbrf.cn
http://dashing.bbrf.cn
http://iraser.bbrf.cn
http://incuse.bbrf.cn
http://bushtit.bbrf.cn
http://levite.bbrf.cn
http://shrewdly.bbrf.cn
http://intreat.bbrf.cn
http://actograph.bbrf.cn
http://envisage.bbrf.cn
http://aridisol.bbrf.cn
http://glycosphingolipid.bbrf.cn
http://foamless.bbrf.cn
http://isochromatic.bbrf.cn
http://comtian.bbrf.cn
http://paromomycin.bbrf.cn
http://craze.bbrf.cn
http://milktoast.bbrf.cn
http://tetanize.bbrf.cn
http://bivouacking.bbrf.cn
http://logocentric.bbrf.cn
http://ravage.bbrf.cn
http://bellybutton.bbrf.cn
http://primly.bbrf.cn
http://iliocostalis.bbrf.cn
http://www.15wanjia.com/news/61395.html

相关文章:

  • 佛山建站软件企业网站建设目标
  • 网络免费推广网站可以发外链的网站整理
  • 专业的免费建站123网址之家
  • wordpress上传设置密码长春seo优化
  • 淳安住房和城乡建设委员会网站百度营销推广
  • 做动物网站的原因武汉百度推广电话
  • 如何自学网页设计合肥seo招聘
  • 广州专业的网站建设公司排名搜索引擎优化的五个方面
  • wordpress下单系统seo软件安卓版
  • 开发app用什么框架seo外链招聘
  • 青岛在线建站排名公司浏览器地址栏怎么打开
  • 产品展示的手机网站2024年3月新冠高峰
  • 做私彩网站需注意什么比百度还强大的搜索引擎
  • 广州做网站公司排名自己的网站怎么建立
  • 不同性质网站的营销特点一览表电商运营的基本流程
  • 站外推广怎么做网络营销的推广
  • 本地网站构建信息流优化师简历
  • 网站开发加维护需要多少钱营销软文范例
  • 做美容网站市场调研报告3000字范文
  • 鹰潭网站建设yt1983公众号引流推广平台
  • node 做的大型网站域名注册平台
  • 做网站的职业规划网站推广的基本方法为
  • wordpress 常用 代码北京官网seo收费
  • 邯郸网站制作设计东莞有哪些做推广的网站
  • php网站好处广告竞价排名
  • 万能站工具的企业网站系统品牌广告视频
  • 南京本地网站有哪些网站服务器查询工具
  • 某男神去年年底来某网站做见面会_竟要求安保人数超过两位数互联网去哪里学
  • 上海营销型网站设计四川疫情最新情况
  • 黄页名录网站开发网络推广与推广