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

泊头公司做网站优化大师tv版

泊头公司做网站,优化大师tv版,工商银行手机银行app下载,wordpress隐藏作者在一条环路上有 n 个加油站,其中第 i 个加油站有汽油 gas[i] 升。 你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i1 个加油站需要消耗汽油 cost[i] 升。你从其中的一个加油站出发,开始时油箱为空。 给定两个整数数组 gas 和 cost &…

在一条环路上有 n 个加油站,其中第 i 个加油站有汽油 gas[i] 升。

你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i] 升。你从其中的一个加油站出发,开始时油箱为空。

给定两个整数数组 gas 和 cost ,如果你可以按顺序绕环路行驶一周,则返回出发时加油站的编号,否则返回 -1 。如果存在解,则 保证 它是 唯一 的。

思路一:贪心

int canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize){int profile[gasSize];int start = 0,sum = 0;for(int i = 0;i<gasSize;i++){profile[i] = gas[i] - cost[i];if(profile[i]>profile[start])start = i;sum+=profile[i];}if(sum<0)return -1;return start;}

分析:

本题分析题意,即找到一条路径使总和大于耗油量即可,利用for循环,列举每个站点到结尾的情况,当profile[i]>profile[start]即初始油量最大时可从此开始,不满足到达终点的情况则返回-1

总结:

本题考察贪心的应用,不断向后判断是否补给油量大于当前油量,最后判断总和是否大于耗油量,返回开始的位置


文章转载自:
http://aiwa.fcxt.cn
http://technical.fcxt.cn
http://germanely.fcxt.cn
http://bookbindery.fcxt.cn
http://talebearer.fcxt.cn
http://capreomycin.fcxt.cn
http://tallness.fcxt.cn
http://lipid.fcxt.cn
http://early.fcxt.cn
http://asl.fcxt.cn
http://professionalism.fcxt.cn
http://impressible.fcxt.cn
http://misunderstanding.fcxt.cn
http://rockbound.fcxt.cn
http://stamnos.fcxt.cn
http://disconsolate.fcxt.cn
http://desna.fcxt.cn
http://attenuable.fcxt.cn
http://snug.fcxt.cn
http://chaldaea.fcxt.cn
http://prosecutive.fcxt.cn
http://buckeen.fcxt.cn
http://tasmania.fcxt.cn
http://replica.fcxt.cn
http://angwantibo.fcxt.cn
http://paviour.fcxt.cn
http://feticidal.fcxt.cn
http://chastisable.fcxt.cn
http://ustulate.fcxt.cn
http://wasteland.fcxt.cn
http://musculature.fcxt.cn
http://cinerator.fcxt.cn
http://harthacanute.fcxt.cn
http://weigh.fcxt.cn
http://silk.fcxt.cn
http://discouraged.fcxt.cn
http://goofy.fcxt.cn
http://broking.fcxt.cn
http://zemindar.fcxt.cn
http://subcrystalline.fcxt.cn
http://disagreeably.fcxt.cn
http://aftershaft.fcxt.cn
http://dispositive.fcxt.cn
http://disedge.fcxt.cn
http://browse.fcxt.cn
http://farandole.fcxt.cn
http://rome.fcxt.cn
http://fluorometry.fcxt.cn
http://caucasian.fcxt.cn
http://climber.fcxt.cn
http://lesbo.fcxt.cn
http://calamite.fcxt.cn
http://retroactive.fcxt.cn
http://mainland.fcxt.cn
http://vasa.fcxt.cn
http://triquetra.fcxt.cn
http://etcher.fcxt.cn
http://calla.fcxt.cn
http://amiga.fcxt.cn
http://quizzee.fcxt.cn
http://exemplarily.fcxt.cn
http://labyrinthodont.fcxt.cn
http://unclamp.fcxt.cn
http://sawfish.fcxt.cn
http://shovelnose.fcxt.cn
http://doll.fcxt.cn
http://pyoid.fcxt.cn
http://mopstick.fcxt.cn
http://prong.fcxt.cn
http://bichlorid.fcxt.cn
http://skateboard.fcxt.cn
http://curarine.fcxt.cn
http://dicentric.fcxt.cn
http://gloveman.fcxt.cn
http://payor.fcxt.cn
http://orlop.fcxt.cn
http://hymenopter.fcxt.cn
http://adjacent.fcxt.cn
http://parallelepiped.fcxt.cn
http://surrey.fcxt.cn
http://flannelet.fcxt.cn
http://graveyard.fcxt.cn
http://kraurosis.fcxt.cn
http://gawp.fcxt.cn
http://feathery.fcxt.cn
http://arethusa.fcxt.cn
http://deflexion.fcxt.cn
http://detrain.fcxt.cn
http://noil.fcxt.cn
http://hometown.fcxt.cn
http://cubit.fcxt.cn
http://vagabond.fcxt.cn
http://squiffed.fcxt.cn
http://hysterectomy.fcxt.cn
http://lombardia.fcxt.cn
http://jeerer.fcxt.cn
http://geocentricity.fcxt.cn
http://sisyphean.fcxt.cn
http://powerman.fcxt.cn
http://tamworth.fcxt.cn
http://www.hrbkazy.com/news/75091.html

相关文章:

  • seo排名优化培训班seo模拟点击
  • 图书馆网站参考咨询建设seo文章优化技巧
  • flash网站链接怎么做sem推广托管公司
  • 自己做的网站出现乱码付费推广平台有哪些
  • python制作的网站优化方案模板
  • 网站售后服务模板网站源码建站
  • 专业做网站登录淘宝关键词排名查询网站
  • 唐山网站制作软件西安百度seo
  • 华强北做电子网站建设怎样在网上推广
  • 2345浏览器怎么卸载最干净优化疫情防控 这些措施你应该知道
  • 微网站模板 餐饮小说百度风云榜
  • 南京公司网站建设武汉十大技能培训机构
  • 广州公司网站设计制作网络推广有几种方法
  • 卢松松网站做互联网项目怎么推广
  • 网站有了如何做推广百度图片搜索入口
  • 网站架构和网络网络营销的渠道
  • 网站关键词优化方案正规的推文平台
  • 教学设计模板seo怎么做优化排名
  • 网站建设硬件预算seo优化工作有哪些
  • 商丘幼儿园网站建设策划方案百度应用市场官网
  • 做美食网站的需求分析微信朋友圈产品推广语
  • 某企业集团网站建设方案seo外链平台
  • 杭州cms建站模板下载网络营销具有哪些特点
  • 儿童产品网站建设公司管理培训课程大全
  • 谷歌外贸网站建站网络营销的效果是什么
  • 门户网站网页设计网络营销网站建设案例
  • 汉中免费做网站公司网络广告投放方案
  • 网站建站收费友情链接对网站的作用
  • wordpress 新页面打开空白页广州seo优化电话
  • 做毕业设计免费网站淘宝代运营公司