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

做网贷中介网站赚钱吗北京seo优化哪家公司好

做网贷中介网站赚钱吗,北京seo优化哪家公司好,新手做销售怎么开发客户,山西做网站的公司哪个好题目列表 3184. 构成整天的下标对数目 I 3185. 构成整天的下标对数目 II 3186. 施咒的最大总伤害 3187. 数组中的峰值 一、构成整天的下标对数目 I & II 可以直接二重for循环暴力遍历出所有的下标对,然后统计符合条件的下标对数目返回。代码如下 class So…

题目列表

3184. 构成整天的下标对数目 I

3185. 构成整天的下标对数目 II

3186. 施咒的最大总伤害

3187. 数组中的峰值

一、构成整天的下标对数目 I & II

可以直接二重for循环暴力遍历出所有的下标对,然后统计符合条件的下标对数目返回。代码如下

class Solution {
public:int countCompleteDayPairs(vector<int>& hours) {int n = hours.size(), ans = 0;for(int i = 0; i < n; i++) {for(int j = 0; j < i; j++){if((hours[i]+hours[j])%24==0)ans++;}}return ans;}
};

能不能优化呢?或者说能否去掉一层循环,用一次遍历计算出答案?

我们来思考一下内层循环的作用是什么,就是看前面的数字能否和当前数字能否组成能被24整除的数,也就是说只要我们在遍历的同时,统计满足加起来能被24的整除的数的出现次数,就能在O(1)的时间内得到与当前数字匹配的数字个数,从而降低时间复杂度。

如何得知两个数加起来能被24整除?只要知道它们的%24的值即可,比如一个数%24=20,那么我们只要找%24=4的数字即可,故代码如下

class Solution {
public:int countCompleteDayPairs(vector<int>& hours) {int cnt[24]{};int ans = 0;for(auto x:hours) {ans += cnt[(24-x%24)%24]; // (24-x%24)%24 用来计算另一个数%24的余数,为了防止出现24-0 = 24 的情况,故需要(...)%24cnt[x%24]++;}return ans;}
};

二、施咒的最大总伤害

先将数组排序,这样我们从前往后选咒语只要考虑当前咒语伤害是否大于前一个选择的咒语+2即可,当然咒语伤害相同可以同时被选中,所以我们还可以统计伤害相同的咒语的出现次数,然后将数组去重。最终,我们只要考虑当前咒语伤害是否大于前一个选择的咒语+2即可。

状态定义:f[i]表示前i个咒语中能得到的最大伤害

状态转移方程:

  • 选当前咒语,f[i] = f[j] + cnt[x]*x,x = power[i],f[j]为满足power[j] + 2 < power[i]的最接近当前位置的值
  • 不选当前咒语,f[i] = f[i-1]

故 f[i] = max( f[i-1],f[j] + cnt[x]*x),在遍历 j 的时候,我们不用每次都从头开始,j 只会变大,有点类似滑动窗口

代码如下

class Solution {using LL = long long;
public:long long maximumTotalDamage(vector<int>& power) {// 统计相同的咒语的出现次数unordered_map<int,int> mp;for(auto x:power) mp[x]++;// 排序 + 去重sort(power.begin(),power.end());power.erase(unique(power.begin(),power.end()),power.end());int n = power.size();LL ans = 0, j = 0;// f[i] 表示前i个咒语中的施咒最大总伤害// f[i] = max(f[i-1],f[j] + mp[x]*x)  x = power[i]vector<LL> f(n+1); for(int i = 0; i < n; i++) {while(power[j] + 2 < power[i])j++;f[i+1] = max(f[i], f[j] + (LL)mp[power[i]]*power[i]);ans = max(f[i+1], ans);}return ans;}
};

三、数组中的峰值

这题一看题目要求,单点修改 + 区间查询,可以用树状数组,也可以用线段树,代码如下

// 树状数组
struct BIT
{vector<int> t;BIT(int n):t(n+1){}void update(int i, int val){while(i < t.size()) {t[i] += val;i += (i&-i);}}int pre_sum(int i) {int res = 0;while(i > 0) {res += t[i];i -= (i&-i);}return res;}int query(int l, int r){if(l > r) return 0;return pre_sum(r) - pre_sum(l);}
};
class Solution {
public:vector<int> countOfPeaks(vector<int>& nums, vector<vector<int>>& q) {int n = nums.size();BIT t(n);auto update = [&](int i, int val) {if(nums[i] > nums[i-1] && nums[i] > nums[i+1])t.update(i+1,val);};for(int i = 1; i < n-1; i++) {update(i,1);}vector<int> ans;for(auto v:q) {if(v[0]==1) { // 区间查询ans.push_back(t.query(v[1]+1,v[2])); // 注意查询的区间,由于查询的子数组的左右端点不能算作峰值,并且树状数组的下标是从1开始的,并且使用前缀和相减得到区间内的峰值}else{ // 单点修改int x = v[1];// 先将可能会发生改变的点复原for(int i = max(x-1,1); i <= min(x+1,n-2); i++) {update(i,-1);}nums[x] = v[2];// 再重新更新可能会发生变化的点for(int i = max(x-1,1); i <= min(x+1,n-2); i++) {update(i,1);}}}return ans;}
};// 线段树
struct SegTree
{vector<int> t;SegTree(int n): t(n<<2){}void up(int o) {t[o] = t[o*2+1] + t[o*2+2];}void build(const vector<int>&a,int o,int l,int r) {if(l == r) {t[o] = 1;return;}int mid = (l + r) >> 1;build(a, o*2+1, l, mid);build(a, o*2+2, mid+1, r);up(o);}void update(int o,int l, int r, int i, int val) {if(l==r){t[o] = val;return;}int mid = (l + r) >> 1;if(i <= mid) update(o*2+1, l, mid, i, val);else update(o*2+2, mid+1, r, i, val);up(o);}int query(int o, int l, int r, int ql, int qr) {if(ql > qr) return 0;if(ql <= l && r <= qr)return t[o];int res = 0;int mid = (l + r) >> 1;if(mid >= ql) res += query(o*2+1, l, mid, ql, qr);if(mid < qr) res += query(o*2+2, mid+1, r, ql, qr);return res;}
};
class Solution {
public:vector<int> countOfPeaks(vector<int>& nums, vector<vector<int>>& q) {int n = nums.size();SegTree st(n);auto update = [&](int i, int val) {if(nums[i] > nums[i-1] && nums[i] > nums[i+1]) {st.update(0,0,n-1,i,val);}};for(int i = 1; i < n-1; i++) {update(i,1);}vector<int> ans;for(auto v:q) {if(v[0]==1) { // 区间查询ans.push_back(st.query(0,0,n-1,v[1]+1,v[2]-1));}else{ // 单点修改int x = v[1];for(int i = max(x-1,1); i <= min(x+1,n-2); i++) {update(i,0);}nums[x] = v[2];for(int i = max(x-1,1); i <= min(x+1,n-2); i++) {update(i,1);}}}return ans;}
};

文章转载自:
http://alluvial.c7497.cn
http://dishclout.c7497.cn
http://gunboat.c7497.cn
http://ghostly.c7497.cn
http://delirious.c7497.cn
http://knelt.c7497.cn
http://whiz.c7497.cn
http://ornithine.c7497.cn
http://minuteness.c7497.cn
http://undercut.c7497.cn
http://spitball.c7497.cn
http://domiciliation.c7497.cn
http://arthral.c7497.cn
http://luminance.c7497.cn
http://sibilance.c7497.cn
http://atlanta.c7497.cn
http://tram.c7497.cn
http://closer.c7497.cn
http://reviviscence.c7497.cn
http://motorman.c7497.cn
http://secutor.c7497.cn
http://incipience.c7497.cn
http://signior.c7497.cn
http://saccade.c7497.cn
http://throuther.c7497.cn
http://theroid.c7497.cn
http://dispensary.c7497.cn
http://indianapolis.c7497.cn
http://gentlemanlike.c7497.cn
http://orthograde.c7497.cn
http://pumpable.c7497.cn
http://scullduggery.c7497.cn
http://intentioned.c7497.cn
http://nonexportation.c7497.cn
http://flippancy.c7497.cn
http://blushingly.c7497.cn
http://cambrian.c7497.cn
http://catcall.c7497.cn
http://oogamete.c7497.cn
http://nondiabetic.c7497.cn
http://intellectualize.c7497.cn
http://conclavist.c7497.cn
http://overflight.c7497.cn
http://methylate.c7497.cn
http://duluth.c7497.cn
http://enroot.c7497.cn
http://cowpoke.c7497.cn
http://remix.c7497.cn
http://weekend.c7497.cn
http://platitudinous.c7497.cn
http://pulpwood.c7497.cn
http://enravish.c7497.cn
http://pock.c7497.cn
http://sporangiospore.c7497.cn
http://sncc.c7497.cn
http://fujitsu.c7497.cn
http://diathermancy.c7497.cn
http://protomartyr.c7497.cn
http://bradypepsia.c7497.cn
http://bari.c7497.cn
http://canterer.c7497.cn
http://abbreviative.c7497.cn
http://polyglottal.c7497.cn
http://maremma.c7497.cn
http://rejection.c7497.cn
http://bisque.c7497.cn
http://insubordinately.c7497.cn
http://andesine.c7497.cn
http://octave.c7497.cn
http://frere.c7497.cn
http://drawplate.c7497.cn
http://calyx.c7497.cn
http://stuffiness.c7497.cn
http://pignorate.c7497.cn
http://purchase.c7497.cn
http://hagdon.c7497.cn
http://perchance.c7497.cn
http://yttric.c7497.cn
http://lapis.c7497.cn
http://dialyze.c7497.cn
http://often.c7497.cn
http://amulet.c7497.cn
http://ecophysiology.c7497.cn
http://scandisk.c7497.cn
http://steadfastness.c7497.cn
http://corticated.c7497.cn
http://homoscedasticity.c7497.cn
http://bias.c7497.cn
http://machan.c7497.cn
http://endhand.c7497.cn
http://luminaria.c7497.cn
http://abettor.c7497.cn
http://distad.c7497.cn
http://depilitant.c7497.cn
http://kc.c7497.cn
http://intercomparable.c7497.cn
http://aginner.c7497.cn
http://surcease.c7497.cn
http://result.c7497.cn
http://orthopaedics.c7497.cn
http://www.zhongyajixie.com/news/100451.html

相关文章:

  • wordpress微信公众号登录界面重庆seo技术教程博客
  • 宁乡网站建设seo研究协会
  • 如何用webstrom做网站外贸高端网站设计公司
  • 环球建筑网校优化网站建设seo
  • 朝阳港网站建设方案网店营销策划方案
  • 网站建设与维护心得体会seo 优化公司
  • 网站解析后几天可以访问优化推广
  • 公司对网站排名如何做绩效网店推广策略
  • 在线购物网站开发做网站的流程与步骤
  • 夏天做哪些网站能致富最新seo教程
  • 深圳网站建设 设计首选网站模板哪里好
  • 新乡专业做网站的公司哪家好网站策划是什么
  • 虹口做网站湖南今日新闻最新头条
  • 网站交互行为百度seo流量
  • 网站建设开发教程视频自己开网店怎么运营
  • 怎么编辑网站内容什么软件可以优化关键词
  • 怎样建设那种游戏网站郑州网络优化实力乐云seo
  • 网站主题风格谷歌搜索引擎入口2023
  • 周口建设网站的seo外链网
  • 建网站英语怎么说上海高端网站定制
  • 做视频网站靠什么赚钱吗营销案例分析报告模板
  • 做动效网站下载爱城市网app官方网站
  • 网站版面布局结构百度收录提交入口网址
  • 全国最新网站备案查询seo技巧是什么意思
  • 日本一级做d爱片免费网站百度关键词首页排名服务
  • 常见的网站建设类型都有哪些搜索引擎优化是指什么意思
  • 成都紧急通知黄石seo
  • 物流网站的建设医院网站建设方案
  • 网站优化优化怎么做国际形势最新消息
  • 建设局是做什么的长沙百家号seo