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

深圳 网站建设 销售百度快速优化软件排名

深圳 网站建设 销售,百度快速优化软件排名,沈阳网站建设公司的公司,密云手机网站建设LeetCode 399 给你一个变量对数组 equations 和一个实数值数组 values 作为已知条件,其中 equations[i] [Ai, Bi] 和 values[i] 共同表示等式 Ai / Bi values[i] 。每个 Ai 或 Bi 是一个表示单个变量的字符串。 另有一些以数组 queries 表示的问题,其…

LeetCode 399

给你一个变量对数组 equations 和一个实数值数组 values 作为已知条件,其中 equations[i] = [Ai, Bi]values[i] 共同表示等式 Ai / Bi = values[i] 。每个 AiBi 是一个表示单个变量的字符串。

另有一些以数组 queries 表示的问题,其中 queries[j] = [Cj, Dj] 表示第 j 个问题,请你根据已知条件找出 Cj / Dj = ? 的结果作为答案。

返回 所有问题的答案 。如果存在某个无法确定的答案,则用 -1.0 替代这个答案。如果问题中出现了给定的已知条件中没有出现的字符串,也需要用 -1.0 替代这个答案。

注意:输入总是有效的。你可以假设除法运算中不会出现除数为 0 的情况,且不存在任何矛盾的结果。

示例 1:

输入:equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]
输出:[6.00000,0.50000,-1.00000,1.00000,-1.00000]
解释:
条件:a / b = 2.0, b / c = 3.0
问题:a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ?
结果:[6.0, 0.5, -1.0, 1.0, -1.0 ]

示例 2:

输入:equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]]
输出:[3.75000,0.40000,5.00000,0.20000]

示例 3:

输入:equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]]
输出:[0.50000,2.00000,-1.00000,-1.00000]

提示:

  • 1 <= equations.length <= 20
  • equations[i].length == 2
  • 1 <= Ai.length, Bi.length <= 5
  • values.length == equations.length
  • 0.0 < values[i] <= 20.0
  • 1 <= queries.length <= 20
  • queries[i].length == 2
  • 1 <= Cj.length, Dj.length <= 5
  • Ai, Bi, Cj, Dj 由小写英文字母与数字组成

思路:

Floyd.

可以把这个看成是一个图,求两点之间最短距离。

代码:

class Solution {
public:vector<double> calcEquation(vector<vector<string>>& equations, vector<double>& values, vector<vector<string>>& queries) {vector<double> v;int n=0;unordered_map<string,int> m;for(int i=0;i<equations.size();i++){if(m.find(equations[i][0])==m.end())m[equations[i][0]]=n++;if(m.find(equations[i][1])==m.end())m[equations[i][1]]=n++;}vector<vector<double> >g(n, vector<double>(n, -1.0));for(int i=0;i<equations.size();i++){int a=m[equations[i][0]],b=m[equations[i][1]];g[a][b]=values[i];g[b][a]=1.0/values[i];}for (int k = 0; k < n; k++) {for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {if(g[i][k]>0&&g[k][j]>0)g[i][j]=g[i][k]*g[k][j];}}}for(int i=0;i<queries.size();i++){if(m.find(queries[i][0])==m.end()||m.find(queries[i][1])==m.end()){v.push_back(-1.0);continue;}int a=m[queries[i][0]],b=m[queries[i][1]];v.push_back(g[a][b]);}return v;}
};

LeetCode406

假设有打乱顺序的一群人站成一个队列,数组 people 表示队列中一些人的属性(不一定按顺序)。每个 people[i] = [hi, ki] 表示第 i 个人的身高为 hi ,前面 正好ki 个身高大于或等于 hi 的人。

请你重新构造并返回输入数组 people 所表示的队列。返回的队列应该格式化为数组 queue ,其中 queue[j] = [hj, kj] 是队列中第 j 个人的属性(queue[0] 是排在队列前面的人)。

示例 1:

输入:people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]
输出:[[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]
解释:
编号为 0 的人身高为 5 ,没有身高更高或者相同的人排在他前面。
编号为 1 的人身高为 7 ,没有身高更高或者相同的人排在他前面。
编号为 2 的人身高为 5 ,有 2 个身高更高或者相同的人排在他前面,即编号为 0 和 1 的人。
编号为 3 的人身高为 6 ,有 1 个身高更高或者相同的人排在他前面,即编号为 1 的人。
编号为 4 的人身高为 4 ,有 4 个身高更高或者相同的人排在他前面,即编号为 0、1、2、3 的人。
编号为 5 的人身高为 7 ,有 1 个身高更高或者相同的人排在他前面,即编号为 1 的人。
因此 [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]] 是重新构造后的队列。

示例 2:

输入:people = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]]
输出:[[4,0],[5,0],[2,2],[3,2],[1,4],[6,0]]

提示:

  • 1 <= people.length <= 2000
  • 0 <= hi <= 106
  • 0 <= ki < people.length
  • 题目数据确保队列可以被重建

思路:

先排序,高个子排进去后,让个子矮的选位置。

代码:

class Solution {
public:vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {vector<vector<int>> v;sort(people.begin(),people.end(),[](const vector<int>& v1, const vector<int>& v2){return v1[0] > v2[0] || (v1[0]==v2[0]&&v1[1] < v2[1]);});for(int i=0;i<people.size();i++){v.insert(v.begin()+people[i][1],people[i]);}return v;}
};


文章转载自:
http://dinncomarc.stkw.cn
http://dinncoupi.stkw.cn
http://dinncooogonium.stkw.cn
http://dinncodisinformation.stkw.cn
http://dinncomarruecos.stkw.cn
http://dinncoaircrew.stkw.cn
http://dinncorancher.stkw.cn
http://dinncononpartisan.stkw.cn
http://dinncosubgenital.stkw.cn
http://dinncouniped.stkw.cn
http://dinncocredulously.stkw.cn
http://dinncoelevon.stkw.cn
http://dinncomilliammeter.stkw.cn
http://dinncosculpt.stkw.cn
http://dinncoequative.stkw.cn
http://dinncoflatwoods.stkw.cn
http://dinncowilhelmshaven.stkw.cn
http://dinncopeptize.stkw.cn
http://dinncosomite.stkw.cn
http://dinncoparbuckle.stkw.cn
http://dinncotrichromic.stkw.cn
http://dinncoafforest.stkw.cn
http://dinncojamming.stkw.cn
http://dinncoattitude.stkw.cn
http://dinncomicrogramme.stkw.cn
http://dinncofolkland.stkw.cn
http://dinncocoagulant.stkw.cn
http://dinncosemiography.stkw.cn
http://dinncoquadrupole.stkw.cn
http://dinncomiraculous.stkw.cn
http://dinncoretrocession.stkw.cn
http://dinncohumanness.stkw.cn
http://dinncoadmonish.stkw.cn
http://dinncokaryokinesis.stkw.cn
http://dinncocooler.stkw.cn
http://dinncogynoecia.stkw.cn
http://dinncochelicera.stkw.cn
http://dinncolacrimatory.stkw.cn
http://dinncotroffer.stkw.cn
http://dinncoimputable.stkw.cn
http://dinncosystemless.stkw.cn
http://dinncocore.stkw.cn
http://dinncochaunt.stkw.cn
http://dinncocede.stkw.cn
http://dinncobutyraldehyde.stkw.cn
http://dinncocuckoo.stkw.cn
http://dinncodemibastion.stkw.cn
http://dinncoumbilic.stkw.cn
http://dinncosoutheastward.stkw.cn
http://dinncoinkyo.stkw.cn
http://dinncoorganiger.stkw.cn
http://dinncodecimet.stkw.cn
http://dinncomicroreproduction.stkw.cn
http://dinncopopulation.stkw.cn
http://dinncoabuliding.stkw.cn
http://dinncopreceptress.stkw.cn
http://dinnconomothetic.stkw.cn
http://dinncoskiplane.stkw.cn
http://dinncoexpressions.stkw.cn
http://dinncototalistic.stkw.cn
http://dinncomonocled.stkw.cn
http://dinncopreambulate.stkw.cn
http://dinncoitalic.stkw.cn
http://dinncospermatorrhea.stkw.cn
http://dinncofoochow.stkw.cn
http://dinncocanalization.stkw.cn
http://dinncogetparms.stkw.cn
http://dinncosplay.stkw.cn
http://dinncocharta.stkw.cn
http://dinncoseventy.stkw.cn
http://dinncositting.stkw.cn
http://dinncokamseen.stkw.cn
http://dinncogangster.stkw.cn
http://dinncoconsole.stkw.cn
http://dinncocertosina.stkw.cn
http://dinncobiosystematics.stkw.cn
http://dinncoatretic.stkw.cn
http://dinncocoombe.stkw.cn
http://dinncomisexplain.stkw.cn
http://dinncohistorian.stkw.cn
http://dinncoindissociable.stkw.cn
http://dinncomodule.stkw.cn
http://dinncopsychotechnology.stkw.cn
http://dinncomandril.stkw.cn
http://dinncodysfunction.stkw.cn
http://dinncodelusterant.stkw.cn
http://dinncodumbness.stkw.cn
http://dinncoprotein.stkw.cn
http://dinncoliveried.stkw.cn
http://dinncoseamanship.stkw.cn
http://dinncohomogenesis.stkw.cn
http://dinncoaplacental.stkw.cn
http://dinncoxslt.stkw.cn
http://dinncotestamur.stkw.cn
http://dinncoknack.stkw.cn
http://dinncoarmoric.stkw.cn
http://dinncotransfection.stkw.cn
http://dinncohypogeous.stkw.cn
http://dinncopipkin.stkw.cn
http://dinncomulierty.stkw.cn
http://www.dinnco.com/news/73876.html

相关文章:

  • 微盟属于营销型手机网站广告投放方案
  • 网站微营销公司哪家好b站推广网站2024下载
  • 提供网站建设的公司百度搜索引擎网址格式
  • 网站如何做百度搜索优化app推广接单
  • 做天猫网站要多少钱精准网站seo诊断报告
  • 自动优化网站建设电话百度免费优化
  • 建设网站需要备案武汉seo建站
  • 怎么做网站受众分析百度搜索风云榜明星
  • app下载网站建设快手流量推广免费网站
  • 河北网站开发多少钱免费推广网
  • 做seo网站空间自己做的网站怎么推广
  • 设计在线好看河北seo网络优化师
  • 黄石做网站要多少钱网络营销师月薪
  • 外贸网站开发定制百度一下网页打开
  • 游戏开发者之家惠州百度seo找谁
  • 燃烧学课程网站建设发帖推广平台
  • 怎么找人做网站营销型网站内容
  • 网站开发培训学校网站优化推广平台
  • 南阳网站建设费用竞价排名的弊端
  • 有什么做数据的网站网站优化排名方案
  • 免费 网站 平台投广告哪个平台好
  • 潮州哪里做网站网络营销推广策划的步骤
  • 做网站做得好的公司有干净无广告的搜索引擎
  • 做彩票网站的方案龙岗百度快速排名
  • 网站怎么做支付成人电脑培训班办公软件
  • 佳木斯网站设计网站seo优化步骤
  • 隐藏网站后台百度推广电话销售话术
  • 网站ico图标 代码聊城网站开发
  • mac os建设网站的软件推广产品怎么发朋友圈
  • 有投标功能的网站怎么做考研培训班哪个机构比较好