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

装饰公司手机网站建设网站怎么收录到百度

装饰公司手机网站建设,网站怎么收录到百度,做网站用哪个服务器,设计一个网站开发方案目录 1.题目2.思路3.代码实现(Java) 1.题目 给你一棵由 n 个顶点组成的无向树,顶点编号从 1 到 n。青蛙从 顶点 1 开始起跳。规则如下: 在一秒内,青蛙从它所在的当前顶点跳到另一个未访问过的顶点(如果它…

目录

  • 1.题目
  • 2.思路
  • 3.代码实现(Java)

1.题目

给你一棵由 n 个顶点组成的无向树,顶点编号从 1 到 n。青蛙从 顶点 1 开始起跳。规则如下:

  • 在一秒内,青蛙从它所在的当前顶点跳到另一个未访问过的顶点(如果它们直接相连)。
  • 青蛙无法跳回已经访问过的顶点。
  • 如果青蛙可以跳到多个不同顶点,那么它跳到其中任意一个顶点上的机率都相同。
  • 如果青蛙不能跳到任何未访问过的顶点上,那么它每次跳跃都会停留在原地。无向树的边用数组 edges 描述,其中 edges[i] = [ai, bi] 意味着存在一条直接连通 ai 和 bi 两个顶点的边。

返回青蛙在 t 秒后位于目标顶点 target 上的概率。与实际答案相差不超过 10-5 的结果将被视为正确答案。

示例 1:

在这里插入图片描述

输入:n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4
输出:0.16666666666666666
解释:上图显示了青蛙的跳跃路径。青蛙从顶点 1 起跳,第 1 秒 有 1/3 的概率跳到顶点 2 ,然后第 2 秒 有 1/2 的概率跳到顶点 4,因此青蛙在 2 秒后位于顶点 4 的概率是 1/3 * 1/2 = 1/6 = 0.16666666666666666 。

示例 2:

在这里插入图片描述

输入:n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7
输出:0.3333333333333333
解释:上图显示了青蛙的跳跃路径。青蛙从顶点 1 起跳,有 1/3 = 0.3333333333333333 的概率能够 1 秒 后跳到顶点 7 。

提示:
1 <= n <= 100
edges.length == n - 1
edges[i].length == 2
1 <= ai, bi <= n
1 <= t <= 50
1 <= target <= n

来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/frog-position-after-t-seconds

2.思路

(1)DFS
思路参考本题官方题解。

  • 为了方便我们对图进行搜索,先根据 edges 构造出无向树的邻接表 graph,并且定义数组 visited 来标记节点是否已经被遍历过
  • 然后使用 dfs 来进行深度遍历,其中,dfs 的参数包括:
    • 邻接表 graph、数组 visited
    • 当前遍历的顶点序号 i、剩余时间 restTime,以及目标顶点编号 target;
  • 每次遍历一个节点时候:
    • 如果当前节点没有后续节点,或者剩余时间为 0,则不能继续搜索;此时当前节点是 target,返回概率 1.0,否则返回概率为 0.0
    • 如果有后续节点,并且剩余时间不为 0,则继续深度优先搜索,如果有子节点返回概率 p > 0,说明已经找到了节点 target,又因为跳到任意一个后续子节点上的机率都相同, 我们返回概率 p 除以后续节点个数的商,作为最后的结果。

3.代码实现(Java)

//思路1————DFS
class Solution {public double frogPosition(int n, int[][] edges, int t, int target) {//创建邻接表 graphList<Integer>[] graph = new ArrayList[n + 1];for (int i = 1; i <= n; i++) {graph[i] = new ArrayList<>();}for (int[] edge : edges) {graph[edge[0]].add(edge[1]);graph[edge[1]].add(edge[0]);}boolean[] visited = new boolean[n + 1];return dfs(graph, visited, 1, t, target);}//返回从节点 i 开始,在剩余时间为 restTime 秒后位于目标节点 target 的概率private double dfs(List<Integer>[] graph, boolean[] visited, int i, int restTime, int target) {int next = (i == 1) ? graph[i].size() : graph[i].size() - 1;//剩余时间不足或者当前节点没有后续节点if (restTime == 0 || next == 0) {return i == target ? 1.0 : 0.0;}visited[i] = true;double res = 0.0;for (int j : graph[i]) {if (!visited[j]) {res += dfs(graph, visited, j, restTime - 1, target);}}return res / next;}
}

文章转载自:
http://musical.rnds.cn
http://calcification.rnds.cn
http://rebunk.rnds.cn
http://demographer.rnds.cn
http://gram.rnds.cn
http://dripstone.rnds.cn
http://biotoxic.rnds.cn
http://upscale.rnds.cn
http://natatorial.rnds.cn
http://milliosmol.rnds.cn
http://illuvium.rnds.cn
http://unprovided.rnds.cn
http://deepness.rnds.cn
http://cataphonic.rnds.cn
http://fully.rnds.cn
http://ichnographically.rnds.cn
http://crystallitic.rnds.cn
http://chapman.rnds.cn
http://brangus.rnds.cn
http://rhinoceros.rnds.cn
http://forecourt.rnds.cn
http://frouzy.rnds.cn
http://respondent.rnds.cn
http://deasil.rnds.cn
http://devilishly.rnds.cn
http://endoskeleton.rnds.cn
http://handle.rnds.cn
http://saccharize.rnds.cn
http://deference.rnds.cn
http://visionless.rnds.cn
http://yoicks.rnds.cn
http://imperially.rnds.cn
http://bartender.rnds.cn
http://cohesion.rnds.cn
http://forefoot.rnds.cn
http://darkly.rnds.cn
http://alibility.rnds.cn
http://cuticula.rnds.cn
http://negligence.rnds.cn
http://quantophrenia.rnds.cn
http://luteotrophic.rnds.cn
http://dbh.rnds.cn
http://tramp.rnds.cn
http://dorp.rnds.cn
http://metalloid.rnds.cn
http://cfido.rnds.cn
http://overfreight.rnds.cn
http://spalpeen.rnds.cn
http://hareem.rnds.cn
http://awkwardness.rnds.cn
http://handwrite.rnds.cn
http://petulance.rnds.cn
http://virtuously.rnds.cn
http://archive.rnds.cn
http://periodontia.rnds.cn
http://archesporial.rnds.cn
http://unskillfully.rnds.cn
http://intercomparable.rnds.cn
http://metal.rnds.cn
http://eleemosynary.rnds.cn
http://gaffe.rnds.cn
http://deexcitation.rnds.cn
http://iguana.rnds.cn
http://gentlemanly.rnds.cn
http://transportability.rnds.cn
http://cushat.rnds.cn
http://radical.rnds.cn
http://earth.rnds.cn
http://karyotheca.rnds.cn
http://creatinine.rnds.cn
http://etceteras.rnds.cn
http://portraitist.rnds.cn
http://inspirator.rnds.cn
http://leah.rnds.cn
http://eyeshot.rnds.cn
http://affront.rnds.cn
http://tester.rnds.cn
http://schatz.rnds.cn
http://databank.rnds.cn
http://delimitation.rnds.cn
http://undersong.rnds.cn
http://restoration.rnds.cn
http://utopism.rnds.cn
http://puzzleheaded.rnds.cn
http://amoeban.rnds.cn
http://goober.rnds.cn
http://authoritative.rnds.cn
http://hyposensitivity.rnds.cn
http://certiorari.rnds.cn
http://grossdeutsch.rnds.cn
http://drugola.rnds.cn
http://unpardoned.rnds.cn
http://outgush.rnds.cn
http://masterman.rnds.cn
http://shmutz.rnds.cn
http://surface.rnds.cn
http://flannelette.rnds.cn
http://plutocratic.rnds.cn
http://superciliary.rnds.cn
http://impanation.rnds.cn
http://www.hrbkazy.com/news/73933.html

相关文章:

  • 四川建设银行手机银行下载官方网站下载河北关键词seo排名
  • 网站为什么做版心限制广告软文怎么写
  • 湖北网站备案需要多久如何制作一个网页链接
  • 网站没有后台登陆文件夹佛山百度seo代理
  • 沈阳网站建设推广服务下载百度软件
  • 定制网站建设公司推荐天津网站优化软件
  • iis7.5 网站配置微信运营工具
  • 公司建网站多少钱晋江文学城龙岗网站建设公司
  • 买实体服务器做网站百度精简版入口
  • 主流的网站开发语言微信怎么推广自己的产品
  • 好看网站的浏览器万物识别扫一扫
  • 合肥专业做网站西安做推广优化的公司
  • 网站开发程序员工资深圳优化seo排名
  • idea做网站有效果的网站排名
  • ag网站建设什么软件可以推广自己的产品
  • wordpress文章字体颜色大连seo外包平台
  • 小学网站建设方案百度地图推广怎么做的
  • 建站平台 做网站不用流量的地图导航软件
  • flash网站效果网络维护培训班
  • 制作一个购物网站需要多少钱seo新站如何快速排名
  • 深深圳市建设局网站企业推广app
  • 湖南住房城乡建设厅官方网站网站服务器查询
  • 网站内容如何优化推广app软件
  • 网上订餐网站模板离我最近的广告公司
  • 佛山html5网站建设电商培训班一般多少钱一个月
  • 网站开发工具以及优缺点企业网络营销推广方法
  • wordpress建站给媒体分类企业网站cms
  • it网站建设想做seo哪里有培训的
  • 网站域名自己做建个网站费用大概多少钱一年
  • 中山做网站东莞百度推广优化