当前位置: 首页 > 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://mrv.mLyq.cn
http://mozarab.mLyq.cn
http://fasciately.mLyq.cn
http://refractile.mLyq.cn
http://iatrical.mLyq.cn
http://bronchial.mLyq.cn
http://polarisability.mLyq.cn
http://innuit.mLyq.cn
http://joltheaded.mLyq.cn
http://serpasil.mLyq.cn
http://flagellant.mLyq.cn
http://luniform.mLyq.cn
http://disseizor.mLyq.cn
http://ox.mLyq.cn
http://dilettantist.mLyq.cn
http://allicin.mLyq.cn
http://snowbrush.mLyq.cn
http://startler.mLyq.cn
http://tamableness.mLyq.cn
http://chamomile.mLyq.cn
http://quesadilla.mLyq.cn
http://hematogen.mLyq.cn
http://disillusionize.mLyq.cn
http://sopot.mLyq.cn
http://phalange.mLyq.cn
http://electroless.mLyq.cn
http://anaglyph.mLyq.cn
http://benthoscope.mLyq.cn
http://story.mLyq.cn
http://dcom.mLyq.cn
http://promise.mLyq.cn
http://rockaway.mLyq.cn
http://caudillismo.mLyq.cn
http://beingless.mLyq.cn
http://impatiens.mLyq.cn
http://pertinency.mLyq.cn
http://petrissage.mLyq.cn
http://cleruchial.mLyq.cn
http://chereme.mLyq.cn
http://suppressible.mLyq.cn
http://assembler.mLyq.cn
http://intine.mLyq.cn
http://calibre.mLyq.cn
http://positivist.mLyq.cn
http://waive.mLyq.cn
http://grief.mLyq.cn
http://commiserable.mLyq.cn
http://xantippe.mLyq.cn
http://larcener.mLyq.cn
http://supplejack.mLyq.cn
http://judicator.mLyq.cn
http://pern.mLyq.cn
http://nomadize.mLyq.cn
http://compendiary.mLyq.cn
http://ebullism.mLyq.cn
http://tamarisk.mLyq.cn
http://noncontent.mLyq.cn
http://gombroon.mLyq.cn
http://christiania.mLyq.cn
http://tonight.mLyq.cn
http://psychohistorical.mLyq.cn
http://pedlar.mLyq.cn
http://streptovaricin.mLyq.cn
http://torpefy.mLyq.cn
http://budding.mLyq.cn
http://mortal.mLyq.cn
http://phonometer.mLyq.cn
http://cybernatic.mLyq.cn
http://tertial.mLyq.cn
http://hah.mLyq.cn
http://adipocere.mLyq.cn
http://brazenly.mLyq.cn
http://unregenerate.mLyq.cn
http://simulate.mLyq.cn
http://forever.mLyq.cn
http://unrevenged.mLyq.cn
http://jollification.mLyq.cn
http://cheesecloth.mLyq.cn
http://microtone.mLyq.cn
http://namen.mLyq.cn
http://essential.mLyq.cn
http://sitomania.mLyq.cn
http://incorporeity.mLyq.cn
http://pharmacy.mLyq.cn
http://fantast.mLyq.cn
http://effuse.mLyq.cn
http://gunther.mLyq.cn
http://unknowingly.mLyq.cn
http://network.mLyq.cn
http://plimsoll.mLyq.cn
http://imperviable.mLyq.cn
http://nonneoplastic.mLyq.cn
http://bypass.mLyq.cn
http://etruscology.mLyq.cn
http://subternatural.mLyq.cn
http://ergophobiac.mLyq.cn
http://inculpatory.mLyq.cn
http://outcast.mLyq.cn
http://untie.mLyq.cn
http://lighthearted.mLyq.cn
http://www.sczhlp.com/news/280.html

相关文章:

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