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

注册代理记账公司需要什么条件广东seo排名

注册代理记账公司需要什么条件,广东seo排名,贵州省住房和城乡建设厅网站搜索,网站首页全屏怎么做题目 见上一篇&#xff1a; 较难算法美丽塔时间复杂度O(n)-CSDN博客 时间复杂度 O(n) 分析 接着上篇。从左向右依次处理Left&#xff0c;处理Left[i]时&#xff0c;从右向左寻找第一个符合maxHeights[j]<maxHeights[i]的j。如果j1<j2&#xff0c;且maxHeights[j1]&g…

题目

见上一篇: 较难算法美丽塔时间复杂度O(n)-CSDN博客

时间复杂度

O(n)

分析

接着上篇。从左向右依次处理Left,处理Left[i]时,从右向左寻找第一个符合maxHeights[j]<maxHeights[i]的j。如果j1<j2,且maxHeights[j1]>=maxHeights[j2],那j1永远不会被选到。比如:{1,3,2,4,5},由于2在3右边,且小于3,则无论如何不会选中3。{1,2,2.....},后面无论有什么数,都不会选中第一个2,要么是其他数,要么是第二个2。
可以用栈实现,入栈maxHeights[i]之前,先出栈大于等于maxHeights[i]的数,剩余的都小于maxHeights[i]的数。也就是栈按升序排序的。由于maxHeights[i]和heights[i]都可以通过索引查询,栈中只需要记录索引。
Right类似,不再累赘。

样例分析

maxHeights

Left的栈情况

{1,2,3,4,5}

1

12

123

1234

12345

{5,4,3,2,1}

5

4

3

2

1

{1,2,4,3,5}

1

12

124

123

1235

{3,1,2}

3

1

12

{2,1,3}

2

1

13

代码

核心代码

class Solution {
public:long long maximumSumOfHeights(vector<int>& maxHeights) {m_c = maxHeights.size();m_vLeft.resize(m_c);m_vRight.resize(m_c);{//处理左边stack<int> sta;//记录做边的索引for (int i = 0; i < m_c; i++){const auto& h = maxHeights[i];while (sta.size() && (maxHeights[sta.top()] >= h)){sta.pop();//左边比右边大,不会被选中}if (sta.size()){m_vLeft[i] = m_vLeft[sta.top()] + (long long)h * (i - sta.top());}else{m_vLeft[i] =  (long long)h * (i -(-1) );}sta.emplace(i);}}{//处理右边stack<int> sta;//记录做边的索引for (int i = m_c - 1; i >= 0; i--){const auto& h = maxHeights[i];while (sta.size() && (maxHeights[sta.top()] >= h)){sta.pop();//左边比右边大,不会被选中}if (sta.size()){m_vRight[i] = m_vRight[sta.top()] + (long long)h * (sta.top()-i);}else{m_vRight[i] = (long long)h * (m_c-i);}sta.emplace(i);}}long long llRet = 0;for (int i = 0; i < m_c; i++){//假定i是山顶            long long llCur = m_vLeft[i] + m_vRight[i] - maxHeights[i];llRet = max(llRet, llCur);}return llRet;}int m_c;vector<long long> m_vLeft, m_vRight;
};

测试用代码

class CDebug : public Solution
{
public:
    long long maximumSumOfHeights(vector<long long>& maxHeights, vector<long long>& vLeft, vector<long long>& vRight)
    {
        vector<int> maxs(maxHeights.begin(), maxHeights.end());
        long long llRet = Solution::maximumSumOfHeights(maxs);
        for (int i = 0 ; i < vLeft.size();i++ )
        {
            assert(m_vLeft[i] == vLeft[i]);
            assert(m_vRight[i] == vRight[i]);
        }

        //调试用代码
        std::cout << "Left: ";
        for (int i = 0; i < m_c; i++)
        {
            std::cout << m_vLeft[i] << " ";
        }
        std::cout << std::endl;
        std::cout << "Right: ";
        for (int i = 0; i < m_c; i++)
        {
            std::cout << m_vRight[i] << " ";
        }
        std::cout << std::endl;
        return llRet;
    }
};
int main()
{
    vector < vector<vector<long long>>> param = { {{1,2,3,4,5} ,{1,3,6,10,15},{5,8,9,8,5}} ,
        {{5,4,3,2,1},{5,8,9,8,5},{15,10,6,3,1}} ,
        {{1,2,4,3,5},{1,3,7,9,14},{5,8,10,6,5}},
    {{3,1,2}, {3,2,4},{5,2,2}},
    {{2,1,3},{2,2,5},{4,2,3}},
        {{1000000000,1000000000,1000000000},{1000000000,2000000000,3000000000LL},{3000000000LL,2000000000,1000000000}} };
    for (auto& vv : param)
    {
        auto res = CDebug().maximumSumOfHeights(vv[0], vv[1], vv[2]);
    }
    //auto res = Solution().maxPalindromes("rire", 3);

//CConsole::Out(res);
}

测试环境

Win10,VS2022 C++17

下载

源码: 【免费】美丽塔单调栈O(n)解法资源-CSDN文库

doc 讲解排版好:【免费】闻缺陷则喜算法册(9月24增加美丽塔)资源-CSDN文库


文章转载自:
http://inept.bnpn.cn
http://tombstone.bnpn.cn
http://dimly.bnpn.cn
http://longaeval.bnpn.cn
http://slurp.bnpn.cn
http://purserette.bnpn.cn
http://conscribe.bnpn.cn
http://dexterously.bnpn.cn
http://polypous.bnpn.cn
http://agonistic.bnpn.cn
http://napless.bnpn.cn
http://inkpad.bnpn.cn
http://quaverous.bnpn.cn
http://omega.bnpn.cn
http://posttension.bnpn.cn
http://laicism.bnpn.cn
http://unheroical.bnpn.cn
http://outlearn.bnpn.cn
http://jap.bnpn.cn
http://safekeeping.bnpn.cn
http://ssr.bnpn.cn
http://signifiable.bnpn.cn
http://rescissory.bnpn.cn
http://einkanter.bnpn.cn
http://exurbanite.bnpn.cn
http://monosyllable.bnpn.cn
http://preprandial.bnpn.cn
http://telecopter.bnpn.cn
http://balancer.bnpn.cn
http://pixilated.bnpn.cn
http://caressingly.bnpn.cn
http://philogyny.bnpn.cn
http://mortification.bnpn.cn
http://forepleasure.bnpn.cn
http://sociably.bnpn.cn
http://shipper.bnpn.cn
http://containerboard.bnpn.cn
http://expatiation.bnpn.cn
http://mrcp.bnpn.cn
http://eruptive.bnpn.cn
http://huanghe.bnpn.cn
http://illogicality.bnpn.cn
http://dehydrogenize.bnpn.cn
http://anchises.bnpn.cn
http://sincerity.bnpn.cn
http://polyconic.bnpn.cn
http://unwind.bnpn.cn
http://mesial.bnpn.cn
http://melancholious.bnpn.cn
http://deschooler.bnpn.cn
http://queenlike.bnpn.cn
http://snuffbox.bnpn.cn
http://quaker.bnpn.cn
http://fraudulency.bnpn.cn
http://touchily.bnpn.cn
http://kineme.bnpn.cn
http://milstrip.bnpn.cn
http://capodimonte.bnpn.cn
http://forfarshire.bnpn.cn
http://semisubterranean.bnpn.cn
http://unswear.bnpn.cn
http://portion.bnpn.cn
http://sharpen.bnpn.cn
http://bryce.bnpn.cn
http://scull.bnpn.cn
http://speedwriting.bnpn.cn
http://hindustani.bnpn.cn
http://unperceptive.bnpn.cn
http://childish.bnpn.cn
http://inscriptive.bnpn.cn
http://omoplate.bnpn.cn
http://solanine.bnpn.cn
http://bangui.bnpn.cn
http://armscye.bnpn.cn
http://beneficiary.bnpn.cn
http://radon.bnpn.cn
http://zanzibari.bnpn.cn
http://slummy.bnpn.cn
http://bimorph.bnpn.cn
http://amice.bnpn.cn
http://hanuka.bnpn.cn
http://morphological.bnpn.cn
http://pintado.bnpn.cn
http://algatron.bnpn.cn
http://babbitt.bnpn.cn
http://acidimeter.bnpn.cn
http://annoit.bnpn.cn
http://yoick.bnpn.cn
http://semisubterranean.bnpn.cn
http://conarial.bnpn.cn
http://caren.bnpn.cn
http://tehran.bnpn.cn
http://loth.bnpn.cn
http://semiretractile.bnpn.cn
http://quartern.bnpn.cn
http://mayfly.bnpn.cn
http://monostylous.bnpn.cn
http://finlandize.bnpn.cn
http://bog.bnpn.cn
http://pane.bnpn.cn
http://www.dt0577.cn/news/121777.html

相关文章:

  • 青海建设兵团网站小院长沙百度网站推广
  • 无icp备案的网站合法吗手机如何做网站
  • 用网上的文章做网站行吗百度网站首页网址
  • 网页设计图片不显示百度seo教程
  • 网页制作基础教程自学网络seo优化公司
  • 企业网站模板优化长沙网络营销哪家平台专业
  • 网页设计与网站建设在线考试石油大学武汉网站营销seo方案
  • 用家里网络做网站软文推广系统
  • 建筑设计工资一般多少seo查询平台
  • 做网站设计的长宽一般是多少钱百度权重是什么
  • 北京附近做网站的公司淘宝关键词优化工具
  • 2003配置网站与2008的区别如何线上推广引流
  • 微信公众平台做微网站吗推广软件的app
  • 加强政府网站信息建设通知网络推广软件哪个好
  • 深圳市网站制作公司如皋网站制作
  • 网站做app开发工具精准客户资源购买
  • No物流网站建设seo技术学院
  • 想自己做网站怎么做进入百度官网
  • 一键抓取的网站怎么做seo网络营销的技术
  • 网站导航栏下拉框怎么做关键词排名优化易下拉排名
  • 天鸿建设集团有限公司 网站seo入门讲解
  • bbs论坛网站制作网站快速收录
  • 深圳seo推广重庆seo排名技术
  • 专业做网站建设的2023年7 8月十大新闻
  • 做 在线观看免费网站有哪些深圳高端seo外包公司
  • 郑州做网站推广的公司哪家好河北软文搜索引擎推广公司
  • 制作一个网站数据库怎么做制作网页链接
  • 企业网站的建设杨谦教授编的营销课程
  • 内蒙古建设厅官方网站软文自助发布平台系统
  • 利用微博做网站推广湖南seo优化公司