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

柳州网站建设推荐网络推广费用计入什么科目

柳州网站建设推荐,网络推广费用计入什么科目,网站模板后台怎么做,北京企业做网站作者推荐 【贪心算法】【中位贪心】.执行操作使频率分数最大 涉及知识点 单调栈 动态规划 map 题目 给定一个整数数组 A,你可以从某一起始索引出发,跳跃一定次数。在你跳跃的过程中,第 1、3、5… 次跳跃称为奇数跳跃,而第 2、…

作者推荐

【贪心算法】【中位贪心】.执行操作使频率分数最大

涉及知识点

单调栈 动态规划 map

题目

给定一个整数数组 A,你可以从某一起始索引出发,跳跃一定次数。在你跳跃的过程中,第 1、3、5… 次跳跃称为奇数跳跃,而第 2、4、6… 次跳跃称为偶数跳跃。
你可以按以下方式从索引 i 向后跳转到索引 j(其中 i < j):
在进行奇数跳跃时(如,第 1,3,5… 次跳跃),你将会跳到索引 j,使得 A[i] <= A[j],A[j] 是可能的最小值。如果存在多个这样的索引 j,你只能跳到满足要求的最小索引 j 上。
在进行偶数跳跃时(如,第 2,4,6… 次跳跃),你将会跳到索引 j,使得 A[i] >= A[j],A[j] 是可能的最大值。如果存在多个这样的索引 j,你只能跳到满足要求的最小索引 j 上。
(对于某些索引 i,可能无法进行合乎要求的跳跃。)
如果从某一索引开始跳跃一定次数(可能是 0 次或多次),就可以到达数组的末尾(索引 A.length - 1),那么该索引就会被认为是好的起始索引。
返回好的起始索引的数量。
示例 1:
输入:[10,13,12,14,15]
输出:2
解释:
从起始索引 i = 0 出发,我们可以跳到 i = 2,(因为 A[2] 是 A[1],A[2],A[3],A[4] 中大于或等于 A[0] 的最小值),然后我们就无法继续跳下去了。
从起始索引 i = 1 和 i = 2 出发,我们可以跳到 i = 3,然后我们就无法继续跳下去了。
从起始索引 i = 3 出发,我们可以跳到 i = 4,到达数组末尾。
从起始索引 i = 4 出发,我们已经到达数组末尾。
总之,我们可以从 2 个不同的起始索引(i = 3, i = 4)出发,通过一定数量的跳跃到达数组末尾。
示例 2:
输入:[2,3,1,1,4]
输出:3
解释:
从起始索引 i=0 出发,我们依次可以跳到 i = 1,i = 2,i = 3:
在我们的第一次跳跃(奇数)中,我们先跳到 i = 1,因为 A[1] 是(A[1],A[2],A[3],A[4])中大于或等于 A[0] 的最小值。
在我们的第二次跳跃(偶数)中,我们从 i = 1 跳到 i = 2,因为 A[2] 是(A[2],A[3],A[4])中小于或等于 A[1] 的最大值。A[3] 也是最大的值,但 2 是一个较小的索引,所以我们只能跳到 i = 2,而不能跳到 i = 3。
在我们的第三次跳跃(奇数)中,我们从 i = 2 跳到 i = 3,因为 A[3] 是(A[3],A[4])中大于或等于 A[2] 的最小值。
我们不能从 i = 3 跳到 i = 4,所以起始索引 i = 0 不是好的起始索引。
类似地,我们可以推断:
从起始索引 i = 1 出发, 我们跳到 i = 4,这样我们就到达数组末尾。
从起始索引 i = 2 出发, 我们跳到 i = 3,然后我们就不能再跳了。
从起始索引 i = 3 出发, 我们跳到 i = 4,这样我们就到达数组末尾。
从起始索引 i = 4 出发,我们已经到达数组末尾。
总之,我们可以从 3 个不同的起始索引(i = 1, i = 3, i = 4)出发,通过一定数量的跳跃到达数组末尾。
示例 3:
输入:[5,1,3,4,2]
输出:3
解释:
我们可以从起始索引 1,2,4 出发到达数组末尾。
提示:
1 <= A.length <= 20000
0 <= A[i] < 100000

代码

单调栈

此方法比map巧妙,性能差不多,值得学习。时间复杂度:O(nlogn)。

变量函数解析

indexs计算奇数跳时,arr[index[i]] 升序,且相等的元素,相对顺序不变。计算偶数跳时,arr[index[i]] 降序,且相等的元素,相对顺序不变。
Next计算奇(偶)数跳的下一个位置,如果无法跳,则值为m_c
vStatus记录偶数(奇数)跳能否跳到队尾。vStatus[0][m_c]和vStatus[0][m_c]为false,避免处理边界条件

Next奇数跳为例

令j=index[jj],按jj从小到的顺序,将j入栈,由于arr[index[jj]]是升序,所以:规则一:arr[栈中元素] <=arr[j]。
(sta.top() < j 成立,说明:
规则二:j在sta.top()右边。
规则三:令index[jj2] 为sta.top(),arr[index(jj2,j)]中的数(即大于等于arr[sta.top()] 同时小于等于arr[j]的数)全部在sta.top()的左边,否则出栈了。
结合规则一二三,stat.top()的下一步就是j。

核心代码

class Solution {
public:int oddEvenJumps(vector<int>& arr) {m_c = arr.size();vector<int> indexs(m_c);iota(indexs.begin(), indexs.end(), 0);sort(indexs.begin(), indexs.end(), [&](const int i1, const int i2) {return (arr[i1] < arr[i2]) || ((arr[i1] == arr[i2]) && (i1 < i2)); });const auto& v1 = Next(indexs);sort(indexs.begin(), indexs.end(), [&](const int i1, const int i2) {return (arr[i1] > arr[i2]) || ((arr[i1] == arr[i2]) && (i1 < i2)); });const auto& v2 = Next(indexs);vector<vector<bool>> vStatus(2, vector<bool>(m_c+1));int iRet = 1;vStatus[0][m_c-1] = true;vStatus[1][m_c - 1] = true;for (int i = m_c - 1 - 1; i >= 0; i--){vStatus[0][i] = vStatus[1][v2[i]];//偶数跳vStatus[1][i] = vStatus[0][v1[i]];//奇数跳iRet +=  (int)vStatus[1][i];}return iRet;}vector<int> Next(const vector<int>& indexs){vector<int> vNext(indexs.size(), indexs.size());stack<int> sta;for (int j : indexs){while (sta.size() && (sta.top() < j)){vNext[sta.top()] = j;sta.pop();}sta.emplace(j);}return vNext;}int m_c;
};

测试用例

template<class T>
void Assert(const T& t1, const T& t2)
{assert(t1 == t2);
}template<class T>
void Assert(const vector<T>& v1, const vector<T>& v2)
{if (v1.size() != v2.size()){assert(false);return;}for (int i = 0; i < v1.size(); i++){Assert(v1[i], v2[i]);}
}int main()
{vector<int> arr;{Solution slu;arr = { 10,13,12,14,15 };auto res = slu.oddEvenJumps(arr);Assert(2, res);}{Solution slu;arr = { 2,3,1,1,4 };auto res = slu.oddEvenJumps(arr);Assert(3, res);}{Solution slu;arr = { 5,1,3,4,2 };auto res = slu.oddEvenJumps(arr);Assert(3, res);}//CConsole::Out(res);
}

2023年3月版:map

利用map性能和单调栈差不多,好理解。从后向前遍历各元素,map的键对应arr[i],map的值对应i。如果arr[i],i小的(后加入的)覆盖前面的。
时间复杂度:O(nlogn)。

map

map可以分成有序(单调)map和无序(哈希)map。还可分成单键map和多键map(允许重复的键)。

 class Solution {public:int oddEvenJumps(vector<int>& arr) {vector<vector<bool>> result;result.assign(arr.size(), vector<bool>(2));result[arr.size() - 1][0] = true;result[arr.size() - 1][1] = true;std::map<int, int> mValueIndex;mValueIndex[arr.back()] = arr.size()-1;for (int i = arr.size() - 2; i >= 0; i--){{//奇数跳跃auto it = mValueIndex.lower_bound(arr[i]);if (mValueIndex.end() != it){result[i][0] = result[it->second][1];}}{//偶数跳跃auto it2 = mValueIndex.upper_bound(arr[i]);if (mValueIndex.begin() != it2){--it2;result[i][1] = result[it2->second][0];}mValueIndex[arr[i]] = i;}}int iNum = 0;for (int i = 0; i < arr.size(); i++){if (result[i][0]){iNum++;}}return iNum;}};

扩展阅读

视频课程

有效学习:明确的目标 及时的反馈 拉伸区(难度合适),可以先学简单的课程,请移步CSDN学院,听白银讲师(也就是鄙人)的讲解。
https://edu.csdn.net/course/detail/38771

如何你想快

速形成战斗了,为老板分忧,请学习C#入职培训、C++入职培训等课程
https://edu.csdn.net/lecturer/6176

相关下载

想高屋建瓴的学习算法,请下载《喜缺全书算法册》doc版
https://download.csdn.net/download/he_zhidan/88348653

我想对大家说的话
闻缺陷则喜是一个美好的愿望,早发现问题,早修改问题,给老板节约钱。
子墨子言之:事无终始,无务多业。也就是我们常说的专业的人做专业的事。
如果程序是一条龙,那算法就是他的是睛

测试环境

操作系统:win7 开发环境: VS2019 C++17
或者 操作系统:win10 开发环境: VS2022 C++17
如无特殊说明,本算法C++ 实现。


文章转载自:
http://goutweed.bfmq.cn
http://delineation.bfmq.cn
http://pulvinus.bfmq.cn
http://epitoxoid.bfmq.cn
http://flechette.bfmq.cn
http://razzia.bfmq.cn
http://knightage.bfmq.cn
http://surprising.bfmq.cn
http://supramaxilla.bfmq.cn
http://thriftily.bfmq.cn
http://felice.bfmq.cn
http://streetworker.bfmq.cn
http://matriarchate.bfmq.cn
http://tasse.bfmq.cn
http://pcte.bfmq.cn
http://conglomerate.bfmq.cn
http://proper.bfmq.cn
http://hearten.bfmq.cn
http://zara.bfmq.cn
http://discerning.bfmq.cn
http://contaminative.bfmq.cn
http://antatrophic.bfmq.cn
http://opiniative.bfmq.cn
http://snaggy.bfmq.cn
http://auditorship.bfmq.cn
http://fabulize.bfmq.cn
http://whortle.bfmq.cn
http://landstream.bfmq.cn
http://caviler.bfmq.cn
http://kriegie.bfmq.cn
http://metacinnabarite.bfmq.cn
http://shakeress.bfmq.cn
http://titularly.bfmq.cn
http://ghetto.bfmq.cn
http://inconvertibility.bfmq.cn
http://subirrigate.bfmq.cn
http://wattmeter.bfmq.cn
http://maxillofacial.bfmq.cn
http://anaglyph.bfmq.cn
http://pneumonolysis.bfmq.cn
http://manoir.bfmq.cn
http://mart.bfmq.cn
http://outweary.bfmq.cn
http://histogenetically.bfmq.cn
http://northerner.bfmq.cn
http://masonite.bfmq.cn
http://plastic.bfmq.cn
http://malaprop.bfmq.cn
http://protoactinium.bfmq.cn
http://gardenia.bfmq.cn
http://patrilinear.bfmq.cn
http://hippology.bfmq.cn
http://polyspermy.bfmq.cn
http://hosteler.bfmq.cn
http://muriate.bfmq.cn
http://dross.bfmq.cn
http://disneyland.bfmq.cn
http://smoko.bfmq.cn
http://cheloid.bfmq.cn
http://roundheel.bfmq.cn
http://unconfiding.bfmq.cn
http://sciurid.bfmq.cn
http://paregoric.bfmq.cn
http://alastrim.bfmq.cn
http://egressive.bfmq.cn
http://brokenly.bfmq.cn
http://designment.bfmq.cn
http://tequila.bfmq.cn
http://ommateum.bfmq.cn
http://icac.bfmq.cn
http://grandstand.bfmq.cn
http://zwinglian.bfmq.cn
http://specula.bfmq.cn
http://skimp.bfmq.cn
http://bailment.bfmq.cn
http://fricando.bfmq.cn
http://thalassocrat.bfmq.cn
http://fusibility.bfmq.cn
http://pellagra.bfmq.cn
http://diathermic.bfmq.cn
http://newly.bfmq.cn
http://tikker.bfmq.cn
http://modena.bfmq.cn
http://eyeglass.bfmq.cn
http://barbaric.bfmq.cn
http://trepidation.bfmq.cn
http://docking.bfmq.cn
http://razzmatazz.bfmq.cn
http://seal.bfmq.cn
http://lionesque.bfmq.cn
http://waterbrain.bfmq.cn
http://accomplishable.bfmq.cn
http://prizefighter.bfmq.cn
http://landownership.bfmq.cn
http://antrim.bfmq.cn
http://insectile.bfmq.cn
http://hopvine.bfmq.cn
http://horsefly.bfmq.cn
http://formalism.bfmq.cn
http://gatepost.bfmq.cn
http://www.dt0577.cn/news/95785.html

相关文章:

  • 网站建设中应该返回502还是301东莞营销网站建设
  • 公司网站域名cn和com热点新闻事件及评论
  • 建设 政务数据共享网站公司网址
  • 网站建设一般要多少费用重庆seo网站排名
  • 沈阳seo网站管理做网络推广的网站有哪些
  • 做外墙资料的网站网页制作的软件
  • 优惠券的网站怎么做免费下载百度并安装
  • 想建设个网站怎么赚钱合肥seo排名公司
  • DW做网站的步骤合肥网站优化
  • 网页开发公司网站公司网站如何seo
  • 对网站建设的具体想法大数据精准客户
  • 怎么用服务器lp做网站站长工具seo综合查询
  • 企业建站项目百度推广好不好做
  • 侯马网站建设百度推广培训机构
  • 网站建设重要新官方app下载安装
  • linux怎么做网站百度云登陆首页
  • 陕西的网站建设公司哪家好软文推广软文营销
  • 网站如何做二级域名seo推广方法集合
  • wordpress 自建模版seo小白入门教学
  • wordpress加微信插件什么是seo文章
  • 网站济南网站建设sem是什么电镜
  • 网站制作中企动力优北大青鸟培训机构官网
  • 单一产品做网站互联网营销师证书含金量
  • 做爰全过程网站免费的视频广西壮族自治区在线seo关键词排名优化
  • 自学做衣服的网站深圳短视频推广
  • 阿里云网站建设最后什么样子百度浏览器官网下载
  • 电商网站分析报告怎么做厦门谷歌推广
  • vi设计网站大全百度识图在线使用一下
  • 兰州做网站的有哪几个惠州关键词排名提升
  • 建设公司自己的网站百度网址大全 简单版