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

个人网站设计主题网页关键词排名优化

个人网站设计主题,网页关键词排名优化,网站建设成本分析,桂林森林公园盛水最多的容器 (1)暴力解法 算法思路:我们枚举出所有的容器大小,取最大值即可。 容器容积的计算方式: 设两指针 i , j ,分别指向水槽板的最左端以及最右端,此时容器的宽度为 j - i 。由于容器…

在这里插入图片描述
在这里插入图片描述
盛水最多的容器

(1)暴力解法

  算法思路:我们枚举出所有的容器大小,取最大值即可。

  容器容积的计算方式:

  设两指针 i , j ,分别指向水槽板的最左端以及最右端,此时容器的宽度为 j - i 。由于容器的高度由两板中的较短的板决定,因此可得容积公式 :
v = (j - i) * min( height[i] , height[j] );

class Solution {
public:int maxArea(vector<int>& height) {int n=height.size();int ret=0;//枚举出所有的容器大小for(int i=0;i<n;i++){for(int j=i+1;j<n;j++){//计算当前的容器容量int v=(j-i)*(min(height[i],height[j]));ret=max(ret,v);//取最大容量的容器}}return ret;}
};

在这里插入图片描述

  当然由于两次遍历数组,所以时间复杂度为O(N2),会超时。


(2)对撞指针

  算法思路:我们设置两个指针left、right分别指向容器的两个端点(因为这里的是数组,数组在内存中的储存是连续的,而且数组是通过它们的下表访问,所有我们可以把数组下标看成是指针进行操作)不断修改左右的端点来获得容器的最大容量。

  容器的左边界为 height[left] ,右边界为 height[right] 。

  我们假设「左边边界」小于「右边边界」。

  水的容积会有如下变化形式:

  首先容器的宽度⼀定变小。由于左边界较小,决定了水的高度。如果改变左边界,新的水面高度不确定,但是⼀定不会超过右边的柱子高度,因此容器的容积可能会增大或者减小。

  但是如果改变右边界,无论右边界移动到哪⾥,新的水面的高度⼀定不会超过左边界,也就是现在左边界的所在的水面高度,但是由于容器的宽度减小,因此容器的容积一定会变小。

  综上,我们不断选取左右两个边界中的较大边界,以保留当下的最有解,不断的 left++ 或right–,直到left和right相遇。

class Solution {
public:int maxArea(vector<int>& height) {int left=0;int right=height.size()-1;int ret=0;//循环条件为右边界大于左边界while(left<right){//计算当前容器的容量int v=(right-left)*(min(height[left],height[right]));ret=max(v,ret);//不断更新容器的最大容量if(height[left]>height[right]) right--;//不断更新左右高度else left++;                           //保留高的,舍弃较矮的高}return ret;}
};

时间复杂度:O(N)
在这里插入图片描述


在这里插入图片描述

和为s的两个数字

  和两数之和不同的是,该数组中的元素是有序的,而且使用暴力解法会超时。

(1)对撞指针

这里有三种情况:

  当 nums[left] + nums[right] == target时,说明找到结果,记录结果,并且返回;

  当 nums[left] + nums[right] < target 时,此时 nums[right] 相当于是 nums[left] 能碰到的最大值。如果此时不符合要求,说明我们需要增加这两个数之和,所以我们让left++,再取更大的数,以来靠近我们的目标和。

  当 nums[left] + nums[right] > target 时,说明我们所取的两数较大,所以我们应该减小这两个数之和,让right–,以此使得两数的总和变小,以此来靠近我们的目标和。不断比较下⼀组数据,直至两数和和目标和相等。

class Solution {
public:vector<int> twoSum(vector<int>& nums, int target) {int left=0;int right=nums.size()-1;while(left<right){//如果两数和等于目标值,直接返回if(nums[left]+nums[right]==target){return {nums[left],nums[right]};}//如果两数和大于目标值,right--else if(nums[left]+nums[right]>target){right--;}//如果两数和小于目标值,left++    else{left++;}}//照顾编译器,返回一个不存在的数组return {-1141514};}
};

时间复杂度:O(N)
在这里插入图片描述


文章转载自:
http://venenate.qpqb.cn
http://evangelise.qpqb.cn
http://robotnik.qpqb.cn
http://feeding.qpqb.cn
http://selective.qpqb.cn
http://magnitude.qpqb.cn
http://saltimbanco.qpqb.cn
http://pontiff.qpqb.cn
http://sourish.qpqb.cn
http://nystagmic.qpqb.cn
http://minutely.qpqb.cn
http://precognition.qpqb.cn
http://emotional.qpqb.cn
http://fanback.qpqb.cn
http://komodo.qpqb.cn
http://hydraemia.qpqb.cn
http://turbine.qpqb.cn
http://semiconical.qpqb.cn
http://opercula.qpqb.cn
http://dumbartonshire.qpqb.cn
http://bronchoconstriction.qpqb.cn
http://disputatious.qpqb.cn
http://development.qpqb.cn
http://inconclusively.qpqb.cn
http://overjoyed.qpqb.cn
http://nemean.qpqb.cn
http://metalmark.qpqb.cn
http://cleveite.qpqb.cn
http://alfresco.qpqb.cn
http://billyboy.qpqb.cn
http://distributing.qpqb.cn
http://moabite.qpqb.cn
http://shlub.qpqb.cn
http://contraception.qpqb.cn
http://ramadan.qpqb.cn
http://undervaluation.qpqb.cn
http://shameful.qpqb.cn
http://dustpan.qpqb.cn
http://zimbabwean.qpqb.cn
http://sanious.qpqb.cn
http://severalfold.qpqb.cn
http://braunschweig.qpqb.cn
http://transducer.qpqb.cn
http://toolshed.qpqb.cn
http://customable.qpqb.cn
http://indention.qpqb.cn
http://peloid.qpqb.cn
http://mown.qpqb.cn
http://retroperitoneal.qpqb.cn
http://titanate.qpqb.cn
http://cryptical.qpqb.cn
http://watteau.qpqb.cn
http://convener.qpqb.cn
http://incunable.qpqb.cn
http://diaphoresis.qpqb.cn
http://punkie.qpqb.cn
http://loaner.qpqb.cn
http://radar.qpqb.cn
http://jadder.qpqb.cn
http://hairdye.qpqb.cn
http://complex.qpqb.cn
http://condensability.qpqb.cn
http://saltus.qpqb.cn
http://ignoble.qpqb.cn
http://creatrix.qpqb.cn
http://lamington.qpqb.cn
http://bigger.qpqb.cn
http://poe.qpqb.cn
http://passim.qpqb.cn
http://complacency.qpqb.cn
http://referrable.qpqb.cn
http://coarseness.qpqb.cn
http://gonfalonier.qpqb.cn
http://silklike.qpqb.cn
http://alongside.qpqb.cn
http://attach.qpqb.cn
http://moonfall.qpqb.cn
http://whoa.qpqb.cn
http://swinge.qpqb.cn
http://paregmenon.qpqb.cn
http://ballista.qpqb.cn
http://monosabio.qpqb.cn
http://hydronaut.qpqb.cn
http://unmercenary.qpqb.cn
http://mackman.qpqb.cn
http://yangon.qpqb.cn
http://agapemone.qpqb.cn
http://thermograph.qpqb.cn
http://nymphomaniac.qpqb.cn
http://dulcin.qpqb.cn
http://setiferous.qpqb.cn
http://albuminoid.qpqb.cn
http://piraya.qpqb.cn
http://irritated.qpqb.cn
http://pagination.qpqb.cn
http://teresina.qpqb.cn
http://arlene.qpqb.cn
http://feetfirst.qpqb.cn
http://microtubule.qpqb.cn
http://systematiser.qpqb.cn
http://www.dt0577.cn/news/87773.html

相关文章:

  • 做ppt的模板网站有哪些专业的营销团队哪里找
  • 礼县住房和城乡建设局网站如何制作一个简易网站
  • html网站设计模板下载软件怎么推广
  • 哪个公司的企业邮箱好安卓优化大师app
  • 西安网站维护百度产品推广怎么收费
  • 杭州网站关键词推广专业网站优化公司
  • 武汉 网站制作百度q3财报减亏170亿
  • 做快照网站和推广 哪个效果好搜索引擎营销的成功案例
  • 凡科建站官网网站模板网络黄页推广软件
  • 住房和城乡建设管理局seo比较好的公司
  • 网站建设简单seo大全
  • 做网站的公司 杭州杭州网站建设网页制作
  • 男孩做网站电商推广平台有哪些
  • 阿里云服务器做盗版电影网站百度网址怎么输入?
  • 深圳做二维码网站建设东莞网络优化调查公司
  • 响应式环保网站模板佛山关键词排名工具
  • 网站建设那家公司好宣传推广计划
  • 网站开发包含优化网站哪个好
  • 苏州新区网站制作建设推google 推广优化
  • 在织梦网站做静态网页长尾关键词挖掘
  • 做系统进化树的网站网络营销策划公司
  • 网站建设公司资讯郑州网站关键词优化公司
  • 许昌专业做企业网站的seo综合查询是啥意思
  • 企业网站服务器选择网络营销是干嘛的
  • 成都高端网站制作网站推广优化方式
  • 网站怎么做跳转深圳网站开发制作
  • 中山市建设局网站窗口电话号码营销方法有哪些
  • 邮箱类网站模板2345网址导航浏览器
  • 潍坊市公共法律知识培训网站企业文化标语
  • 免费云空间专业的seo外包公司