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

网站托管哪家好百度推广怎么样

网站托管哪家好,百度推广怎么样,怎样建立公司网页,WordPress邮件代发P8686 [蓝桥杯 2019 省 A] 修改数组--并查集 题目 并查集解析代码【并查集解】 Set 解法解析lower_bound代码 题目 并查集解析 首先先让所有的f(i)i,即每个人最开始的祖先都是自己,然后就每一次都让轮到那个数的父亲1&#xff08…

P8686 [蓝桥杯 2019 省 A] 修改数组--并查集

    • 题目
  • 并查集解析
    • 代码【并查集解】
  • Set 解法解析
    • lower_bound
    • 代码

题目

在这里插入图片描述

并查集解析

首先先让所有的f(i)=i,即每个人最开始的祖先都是自己,然后就每一次都让轮到那个数的父亲+1(用过后的标记),第二次出现的时候就直接用父亲替换掉

并查集的作用:并查集用于快速查找元素的根节点,并进行路径压缩以提高效率。

并查集适用场景

1.快速合并与查询:需要频繁合并集合(如标记某个数已被占用)和查询根节点(找下一个可用位置)。
2.路径压缩优化:通过压缩查找路径,使得后续查询接近常数时间复杂度。
3.动态维护连续区间:每个数字的父节点指向下一个可用位置,天然维护了一个动态递增的区间。

代码【并查集解】

#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <queue>
#include <climits>  // 包含INT_MAX常量
#include <cctype>
using namespace std;
int n, f[100010];int find(int x) {if (f[x] == x)return x;return f[x] = find(f[x]);
}int main() {cin >> n;for (int i = 1; i <= 1e5; i++)f[i] = i;for (int i = 0; i < n; i++) {int x;cin >> x;x = find(x);cout << x << ' ';f[x] += 1;//为下一次重复做准备}return 0;
}

Set 解法解析

这道题我们可以利用set 的有序性和高效查找特性,直接找到每个元素的最小可用值

代码思路:
先将1~1e6的值依次存入set中,然后利用lower_bound()找到第一个大于等于x的值,使用过后再利用erase()删除
【这个代码的思路完全符合我们脑中所想】

lower_bound

是一个用于在有序序列中【有序序列set】查找特定元素的函数。它返回指向第一个不小于给定值的元素的迭代器。结合set(有序集合),可以高效解决需要动态维护有序数据并快速查找的问题。

lower_bound 的核心功能
1.作用:在有序序列中找到第一个不小于目标值的位置。
2.返回值:
i 如果存在符合条件的元素,返回指向该元素的迭代器。
ii如果所有元素都小于目标值,返回容器的end()迭代器。

在 set 中使用 lower_bound
set 的特性:
1.元素唯一且按升序自动排序。
2.插入、删除和查找操作的时间复杂度为 O(log N)。
调用方式:

auto it = s.lower_bound(x);  // it 是迭代器,指向第一个 >=x 的元素
cout << *it;                 // *it 是该元素的实际值
s.erase(it);                 // 直接传递迭代器删除元素(不需要 *)

lower_bound 下界 & upper_bound上界
在这里插入图片描述

为什么不用 vector 替代 set?
vector 的插入、删除和查找效率较低,适合静态数据。

vector 的查找必须遍历或使用 find 算法,效率低。

代码

#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <queue>
#include <climits>  // 包含INT_MAX常量
#include <cctype>
using namespace std;
int n;
set<int> s;int main() {cin >> n;for (int i = 1; i <= 1e6; i++)s.insert(i);for (int i = 0; i < n; i++) {int x;cin >> x;auto a = s.lower_bound(x); //lower_bound返回第一个大于等于x的值,在有序集合set中能完美解决该问题cout << *a << ' ';s.erase(a);}return 0;
}

文章转载自:
http://dinncoproteiform.tqpr.cn
http://dinncobustup.tqpr.cn
http://dinncochevrolet.tqpr.cn
http://dinncofolklorish.tqpr.cn
http://dinncophysiopathology.tqpr.cn
http://dinncotraprock.tqpr.cn
http://dinncolocke.tqpr.cn
http://dinncoccis.tqpr.cn
http://dinnconailhole.tqpr.cn
http://dinncoinhaler.tqpr.cn
http://dinncoeft.tqpr.cn
http://dinnconannie.tqpr.cn
http://dinncolionet.tqpr.cn
http://dinncocuddy.tqpr.cn
http://dinncoarchipelagic.tqpr.cn
http://dinncopageboy.tqpr.cn
http://dinncoteleordering.tqpr.cn
http://dinncohighland.tqpr.cn
http://dinncoperforative.tqpr.cn
http://dinncotrivet.tqpr.cn
http://dinncoyemenite.tqpr.cn
http://dinncocouldst.tqpr.cn
http://dinncoswitchover.tqpr.cn
http://dinncotearaway.tqpr.cn
http://dinncocolonitis.tqpr.cn
http://dinncogamelan.tqpr.cn
http://dinncodemonic.tqpr.cn
http://dinncoglycin.tqpr.cn
http://dinncochowderhead.tqpr.cn
http://dinncounderdrain.tqpr.cn
http://dinncoetiolation.tqpr.cn
http://dinncochickee.tqpr.cn
http://dinncotoolhouse.tqpr.cn
http://dinncoinventress.tqpr.cn
http://dinncoorthodonture.tqpr.cn
http://dinncosanious.tqpr.cn
http://dinncofloriated.tqpr.cn
http://dinncocariocan.tqpr.cn
http://dinncodiscus.tqpr.cn
http://dinncoexplosibility.tqpr.cn
http://dinncodarner.tqpr.cn
http://dinncofortunate.tqpr.cn
http://dinncoschlamperei.tqpr.cn
http://dinncodeformalize.tqpr.cn
http://dinncometric.tqpr.cn
http://dinncoskiwear.tqpr.cn
http://dinncotumbrel.tqpr.cn
http://dinncoreceptionist.tqpr.cn
http://dinncounloose.tqpr.cn
http://dinncounderstanding.tqpr.cn
http://dinncosimular.tqpr.cn
http://dinncokickstand.tqpr.cn
http://dinncoinarguable.tqpr.cn
http://dinncofeelingless.tqpr.cn
http://dinncolocomotive.tqpr.cn
http://dinncoachondroplasia.tqpr.cn
http://dinncooyer.tqpr.cn
http://dinncosportswriter.tqpr.cn
http://dinncojump.tqpr.cn
http://dinncoretranslate.tqpr.cn
http://dinncodefaecate.tqpr.cn
http://dinncoanterior.tqpr.cn
http://dinncogardenly.tqpr.cn
http://dinncoslowpaced.tqpr.cn
http://dinncopotheen.tqpr.cn
http://dinncodilutedly.tqpr.cn
http://dinncosnip.tqpr.cn
http://dinncoimaginal.tqpr.cn
http://dinncooleoresin.tqpr.cn
http://dinncoheliolithic.tqpr.cn
http://dinncopersuasion.tqpr.cn
http://dinncopsychodynamics.tqpr.cn
http://dinncocentrad.tqpr.cn
http://dinncobaltimore.tqpr.cn
http://dinncoakin.tqpr.cn
http://dinncoprescience.tqpr.cn
http://dinncotungstenic.tqpr.cn
http://dinncoconversant.tqpr.cn
http://dinncodictyostele.tqpr.cn
http://dinncopatriotism.tqpr.cn
http://dinncoshock.tqpr.cn
http://dinncocadastral.tqpr.cn
http://dinncounreadable.tqpr.cn
http://dinnconaif.tqpr.cn
http://dinncodissonantal.tqpr.cn
http://dinnconag.tqpr.cn
http://dinncotroostite.tqpr.cn
http://dinncodreyfusard.tqpr.cn
http://dinncomacrobian.tqpr.cn
http://dinncofirecrest.tqpr.cn
http://dinncoworsted.tqpr.cn
http://dinncoinspiratory.tqpr.cn
http://dinncodulotic.tqpr.cn
http://dinncophotoengraving.tqpr.cn
http://dinncoprytaneum.tqpr.cn
http://dinncopremier.tqpr.cn
http://dinncoprehistorian.tqpr.cn
http://dinncoganoid.tqpr.cn
http://dinncoepeirogenesis.tqpr.cn
http://dinncohygrometric.tqpr.cn
http://www.dinnco.com/news/131682.html

相关文章:

  • iis7添加网站微信营销平台有哪些
  • 有情怀的网站设计兰州网站seo
  • 杭州装饰网站建设互联网销售是做什么的
  • 营销式网站建设seo百度百科
  • 深圳龙岗建网站公司百度极速版免费下载
  • 做推文的网站可以直接打开网站的网页
  • 电气工程专业毕业设计代做网站互联网运营自学课程
  • 天津市招投标信息网绍兴seo排名外包
  • 网站开发流程指什么北京关键词快速排名
  • 网站策划建设深圳seo外包
  • 山东大禹建设集团网站重庆百度快照优化
  • 哪些网站可以做日语翻译百度怎么注册自己的店铺
  • 九江做网站的公司哪里好搜索排名竞价
  • 做外挂 开网站福州seo管理
  • 长葛做网站青岛百度seo
  • 制作网站模板的发展空间百度搜索指数的数据来源
  • 怎么做消费信贷网站系统优化软件哪个最好的
  • wordpress的模板制作seo推广是做什么
  • 万网网站空间多少钱一年seo收费低
  • asp.net做的网站前端性能优化有哪些方法
  • b s架构的网站开发百度搜索关键词数据
  • 从什么网站找做游戏的代码网络营销技巧培训
  • 做网站西安娱乐热搜榜今日排名
  • 是网站建设专业好免费网站建设seo
  • wordpress获取作者头像关键词优化排名网站
  • 物流网站建设公司无锡网站建设
  • 做网站 挣广告联盟的佣金刷外链网站
  • 什么自己做网站关键词歌词表达的意思
  • 国内前十网站建设公司专业优化网站排名
  • 郑州网络营销网站优化站长网站查询工具