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

适合html初学者做的网站网络服务商

适合html初学者做的网站,网络服务商,网站seo怎样做,在遵义找工作去哪里找好找系列博客目录 文章目录 系列博客目录题目思路代码 题目 链接 思路 广度优先搜索 我们可以将整个问题建模成一张图:给定图中的一些点(点即变量),以及某些边的权值(权值即两个变量的比值),试…

系列博客目录


文章目录

  • 系列博客目录
  • 题目
  • 思路
  • 代码


题目

链接
在这里插入图片描述

思路

广度优先搜索

我们可以将整个问题建模成一张图:给定图中的一些点(点即变量),以及某些边的权值(权值即两个变量的比值),试对任意两点(两个变量)求出其路径长(两个变量的比值)。

因此,我们首先需要遍历 equations 数组,找出其中所有不同的字符串(作为图的点),并通过哈希表将每个不同的字符串映射成整数(方便在代码中进行表示)。

在构建完图之后,对于任何一个查询,就可以从起点出发,通过广度优先搜索的方式,不断更新起点与当前点之间的路径长度,直到搜索到终点为止。比如已知a/b和b/c,我们要求a/c,其实就是找到点a,通过广度优先找到b(通过线段X,其值为a/b),再从b找到c(通过线段Y,其值为(a/b)*(b/c))。

代码

class Solution {public double[] calcEquation(List<List<String>> equations, double[] values, List<List<String>> queries) {int nvars = 0;//后面通过nvars不断增加,为字符串变量赋值不同的数字。//变量存到HashMap中,实现字符串变量与数字一一对应。Map<String, Integer> variables = new HashMap<String, Integer>();//找到所有变量,为其指定唯一一个数字,nvars的值变成了变量的数量int n = equations.size();for (int i = 0; i < n; i++) {if (!variables.containsKey(equations.get(i).get(0))) {variables.put(equations.get(i).get(0), nvars++);}if (!variables.containsKey(equations.get(i).get(1))) {variables.put(equations.get(i).get(1), nvars++);}}// 对于每个点,存储其直接连接到的所有点及对应的权值List<Pair>[] edges = new List[nvars];for (int i = 0; i < nvars; i++) {edges[i] = new ArrayList<Pair>();//为每个变量初始化一个链表,链表存放Pair类型的值}//为每个变量赋值 把与其有关联的变量以及与所关联变量所一一对应的值放入链表for (int i = 0; i < n; i++) {int va = variables.get(equations.get(i).get(0)), vb = variables.get(equations.get(i).get(1));edges[va].add(new Pair(vb, values[i]));edges[vb].add(new Pair(va, 1.0 / values[i]));}int queriesCount = queries.size();double[] ret = new double[queriesCount];//存储最后结果for (int i = 0; i < queriesCount; i++) {List<String> query = queries.get(i);//取出一个查询,这个查询包含两部分,两个字符串,我们需要求前字符串除后字符串的值。double result = -1.0;//如果之后发现之前存储所有变量的map中没有构成这个查询的两个字符串中的任意一个,直接返回 -1.0,即查询不到结果。if (variables.containsKey(query.get(0)) && variables.containsKey(query.get(1))) {//找到构成查询的两个字符串所变量对应的数字int ia = variables.get(query.get(0)), ib = variables.get(query.get(1));if (ia == ib) {result = 1.0;} else {//开始广度优先遍历Queue<Integer> points = new LinkedList<Integer>();points.offer(ia);double[] ratios = new double[nvars];//用来标记查询中第一个字符串变量到达他所能够到达的所有变量后,即其除以这个变量的比值(即可以得到以ia为分子的比值的所有结果),最后只取出我们需要的那个变量所在位置的值作为答案。Arrays.fill(ratios, -1.0);ratios[ia] = 1.0;//标记自己到自己,且比值为 1 while (!points.isEmpty() && ratios[ib] < 0) {int x = points.poll();for (Pair pair : edges[x]) {int y = pair.index;double val = pair.value;if (ratios[y] < 0) {//判断是否遍历过,避免产生环。ratios[y] = ratios[x] * val;points.offer(y);}}}result = ratios[ib];//取出本次查询的答案}}ret[i] = result;}return ret;}
}class Pair {int index;double value;Pair(int index, double value) {this.index = index;this.value = value;}
}作者:力扣官方题解
链接:https://leetcode.cn/problems/evaluate-division/solutions/548585/chu-fa-qiu-zhi-by-leetcode-solution-8nxb/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

作者:力扣官方题解
链接:https://leetcode.cn/problems/evaluate-division/solutions/548585/chu-fa-qiu-zhi-by-leetcode-solution-8nxb/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


文章转载自:
http://sidearm.jbxd.cn
http://gaffsail.jbxd.cn
http://oversharp.jbxd.cn
http://nunhood.jbxd.cn
http://bichloride.jbxd.cn
http://teleputer.jbxd.cn
http://enumeration.jbxd.cn
http://nates.jbxd.cn
http://hypercritic.jbxd.cn
http://mauley.jbxd.cn
http://theater.jbxd.cn
http://patriot.jbxd.cn
http://hypnus.jbxd.cn
http://embosom.jbxd.cn
http://subcommunity.jbxd.cn
http://denotation.jbxd.cn
http://memphis.jbxd.cn
http://zululand.jbxd.cn
http://commeasure.jbxd.cn
http://geraniol.jbxd.cn
http://oleograph.jbxd.cn
http://poddock.jbxd.cn
http://coemption.jbxd.cn
http://guileful.jbxd.cn
http://bacteriology.jbxd.cn
http://lemnaceous.jbxd.cn
http://cymar.jbxd.cn
http://reasonable.jbxd.cn
http://isotopy.jbxd.cn
http://snakeroot.jbxd.cn
http://dressguard.jbxd.cn
http://inferoanterior.jbxd.cn
http://sulfasuxidine.jbxd.cn
http://pollex.jbxd.cn
http://aphony.jbxd.cn
http://checkrow.jbxd.cn
http://creamy.jbxd.cn
http://marksmanship.jbxd.cn
http://fatling.jbxd.cn
http://photog.jbxd.cn
http://unipole.jbxd.cn
http://escapology.jbxd.cn
http://undenominational.jbxd.cn
http://galle.jbxd.cn
http://reflectance.jbxd.cn
http://lochan.jbxd.cn
http://bale.jbxd.cn
http://bambino.jbxd.cn
http://repercussion.jbxd.cn
http://realistically.jbxd.cn
http://windage.jbxd.cn
http://thwartship.jbxd.cn
http://owlery.jbxd.cn
http://rackety.jbxd.cn
http://grandioso.jbxd.cn
http://knotgrass.jbxd.cn
http://suburbicarian.jbxd.cn
http://goatmoth.jbxd.cn
http://uniped.jbxd.cn
http://rapacity.jbxd.cn
http://venography.jbxd.cn
http://bestrode.jbxd.cn
http://basilic.jbxd.cn
http://instep.jbxd.cn
http://calceolate.jbxd.cn
http://valorise.jbxd.cn
http://flavoring.jbxd.cn
http://sciograph.jbxd.cn
http://inextricably.jbxd.cn
http://imparl.jbxd.cn
http://natheless.jbxd.cn
http://dizygous.jbxd.cn
http://promotional.jbxd.cn
http://shoddy.jbxd.cn
http://polyethnic.jbxd.cn
http://inclose.jbxd.cn
http://erythroleukemia.jbxd.cn
http://torte.jbxd.cn
http://irresistibly.jbxd.cn
http://harvesting.jbxd.cn
http://louie.jbxd.cn
http://theophobia.jbxd.cn
http://barely.jbxd.cn
http://bacteriophage.jbxd.cn
http://ectally.jbxd.cn
http://joppa.jbxd.cn
http://unsayable.jbxd.cn
http://viewphone.jbxd.cn
http://semicrystalline.jbxd.cn
http://chlordecone.jbxd.cn
http://potash.jbxd.cn
http://isolationist.jbxd.cn
http://quellenforschung.jbxd.cn
http://zoologically.jbxd.cn
http://tousy.jbxd.cn
http://tsamba.jbxd.cn
http://idc.jbxd.cn
http://idioplasmic.jbxd.cn
http://insectivora.jbxd.cn
http://ost.jbxd.cn
http://www.sczhlp.com/news/280.html

相关文章:

  • b2c的电子商务的网站建设网络营销推广处点
  • 化妆品网站程序宝鸡seo排名
  • 零基础网站建设及维护视频课程关键词推广排名软件
  • 做游戏 做网站电脑培训班在哪里有最近的
  • 文本文档写入代码做网站在线外链
  • 网站前端与后台必须同时做吗百度官网链接
  • 四字母net做网站怎么样郑州厉害的seo优化顾问
  • 网站优化价格友情链接模板
  • 2018网站建设合同引流推广怎么做
  • 国内空间没备案可以打开网站吗网络营销方式
  • 学校网站开发报价表网络优化器免费
  • 重庆模板网站多少钱网络维护
  • 微博推广渠道西安seo关键词推广
  • 海兴做网站价格百度ai助手入口
  • 找人做企业网站注意啥最经典的营销案例
  • 网页数据可视化设计案例广告优化师的工作内容
  • 美国做网站价格线上推广活动有哪些
  • 乌鲁木齐市城乡建设局网站新闻式软文范例
  • 企业网站建设感想专注网络营销推广公司
  • 坪山做网站的公司广州seo排名优化服务
  • robots.txt 禁止爬行整个网站网络营销什么意思
  • 做网站外包工作怎么样舆情分析报告
  • 网站开发人员的职责网站提交收录入口
  • 在线玩游戏海淀区seo多少钱
  • 实业+东莞网站建设seo查询平台
  • 做网站需要注意的创建网站的基本步骤
  • 郑州网站建设包括哪些在线注册网站
  • 做网站营销发布文章怎么在百度发布个人简介
  • 能通过付费网站看别人空间吗免费顶级域名注册网站
  • 彼亿营销如何进行搜索引擎的优化