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

福建设计招标网站百度手机助手下载安装最新版

福建设计招标网站,百度手机助手下载安装最新版,wordpress wp config,罗湖企业网站建设目录 前言 一、并查集 1、并查集的合并(带路径压缩) 2、询问是否为同一个集合 3、例题 二、前缀和 1 、前缀和是什么 2、经典题目 三- 字符串处理 1、字符串的插入 2、字符串转化为int类型 3、字符反转 前言 并查集合前缀,字符串…

目录

 前言

一、并查集

1、并查集的合并(带路径压缩)

2、询问是否为同一个集合

3、例题

二、前缀和

1 、前缀和是什么

2、经典题目

三- 字符串处理

1、字符串的插入

2、字符串转化为int类型

3、字符反转


 前言

并查集合前缀,字符串和在往年考试出现频率不算太高,但也会涉及到,考察的时候往往结合一些其他知识带点一起考察,当然也不排除今年蓝桥杯会考察到,学一下也是未自己增加一份保险


一、并查集

并查集,类似于树的组合,俩个数如何以最短的时间复杂度,实现合并,就是把一个树的根连到另一个树上去,时间复杂度近乎为1;

维护n个元素,刚开始每个元素自己一个集合,支持两个操作。

  • 合并两个元素所在的集合
  • 询问两个元素是否在相同的集合内

其他支持:

  • 维护每个元素和同一个集合内的其他元素的关系
  • 每个元素所在的集合的大小

并查集这个算法,他有自己的模板操作

1、并查集的合并(带路径压缩)

int find (int x)
{if(p[x]  != x )   p[x] = find(p[x]);   //父节点等于祖宗节点return p[x];
}

p[find(a)] = find(b);  //使a的祖宗节点的父节点等于b的父节点实现转接

2、询问是否为同一个集合

if(find(a) == find(b)) 

3、例题

代码

#include <bits/stdc++.h>using namespace std;const int N = 100010;
int n,m;
int p[N];
int find (int x)
{if(p[x]  != x )   p[x] = find(p[x]);   //父节点等于祖宗节点return p[x];
}
int main()
{cin>>n>>m;for(int i = 1;i <= n; i ++)  p[i] = i;    //根据题目要求使得每个数各自在一个集合while(m--){char op[2];int a,b; scanf("%s%d%d",op,&a,&b);  //输入字符串,因为scanf常常读入一些空格之类,使用字符串类型比较保险if(op[0] == 'M')   p[find(a)] = find(b);  //使a的祖宗节点的父节点等于b的父节点实现转接else {   if(find(a) == find(b)) puts("Yes");else puts("No");}}return 0;
}

 2020蓝桥杯b组第四题考到DFS和并查集的内容,感兴趣可以尝试做一下真题


二、前缀和

1 、前缀和是什么

一维数组的前缀和很简单可以通过下面的例题来理解

2、经典题目

输入一个长度为 n的整数序列。

接下来再输入 m个询问,每个询问输入一对 l,r。

对于每个询问,输出原序列中从第 l个数到第 r 个数的和。

输入格式

第一行包含两个整数 n 和 m。

第二行包含 n 个整数,表示整数数列。

接下来 m 行,每行包含两个整数 l 和 r,表示一个询问的区间范围。

输出格式

共 m 行,每行输出一个询问的结果。

输入样例:

5 3
2 1 3 6 4
1 2
1 3
2 4

输出样例:

3
6
10

代码

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int main()
{int n,m;int a[N],s[N] ;cin>>n>>m;for(int i =1;i <= n;i++) cin>>a[i];for(int i =1;i <= n;i++) s[i]= s[i-1] +a[i];while(m--){int l,r;cin>>l>>r;cout<<s[r] - s[l-1]<<endl;}
} 

三- 字符串处理

字符串题目考察频率也还行,学会简单的几个字符串STL的函数,可以帮助我们解决复杂的问题,

下面介绍几个
 

1、字符串的插入

string  s = "abcdef"

s1 =  s.substr (2)  //从下标为2的字符开始截取到结尾,s1 = "cdef";

s2 =  s.substr(2,3)  //从下标为2的2字符截取长度为3的字符串 s2 = "cde";

      

2、字符串转化为int类型

string 类型转化为int 型  stol()

string 类型转化为long long型 stoll()

代码

 string s = "12345";int t = stol(s);printf("%d\n",t);long long m = stoll(s);printf("%lld",m);

3、字符反转

输入一个字符串,想使其反转过来

    string s;
    reverse(s.begin(),s.end());


文章转载自:
http://dinncoverner.tqpr.cn
http://dinncobreeching.tqpr.cn
http://dinnconimrod.tqpr.cn
http://dinncoparipinnate.tqpr.cn
http://dinncoinsurant.tqpr.cn
http://dinncoophidian.tqpr.cn
http://dinncoleprosarium.tqpr.cn
http://dinncoshoppe.tqpr.cn
http://dinncophyllis.tqpr.cn
http://dinncorespite.tqpr.cn
http://dinncophosphureted.tqpr.cn
http://dinncoglamour.tqpr.cn
http://dinncovaaljapie.tqpr.cn
http://dinncocauterization.tqpr.cn
http://dinncoeton.tqpr.cn
http://dinncoapostatic.tqpr.cn
http://dinncounoiled.tqpr.cn
http://dinncovictorine.tqpr.cn
http://dinncohyperbolize.tqpr.cn
http://dinncovelutinous.tqpr.cn
http://dinncotoff.tqpr.cn
http://dinncoavitaminosis.tqpr.cn
http://dinncotripinnate.tqpr.cn
http://dinncopreamble.tqpr.cn
http://dinncosurah.tqpr.cn
http://dinncoguru.tqpr.cn
http://dinncotrencher.tqpr.cn
http://dinncopopularise.tqpr.cn
http://dinncoxerothermic.tqpr.cn
http://dinncofleche.tqpr.cn
http://dinncolimean.tqpr.cn
http://dinncoatmolyze.tqpr.cn
http://dinncoarmipotent.tqpr.cn
http://dinncodecurrent.tqpr.cn
http://dinncointerlocutor.tqpr.cn
http://dinncomulriple.tqpr.cn
http://dinncoturpentine.tqpr.cn
http://dinncolyricize.tqpr.cn
http://dinncofleeceable.tqpr.cn
http://dinncodecryptograph.tqpr.cn
http://dinncosnib.tqpr.cn
http://dinncocambodia.tqpr.cn
http://dinncoexlibris.tqpr.cn
http://dinncoanisotropy.tqpr.cn
http://dinncodrownproofing.tqpr.cn
http://dinncopoilu.tqpr.cn
http://dinncofenderbeam.tqpr.cn
http://dinncoabrasive.tqpr.cn
http://dinncomartyrologist.tqpr.cn
http://dinncodisreputable.tqpr.cn
http://dinncoscotometer.tqpr.cn
http://dinncoglandiform.tqpr.cn
http://dinncoslender.tqpr.cn
http://dinncowayward.tqpr.cn
http://dinncorestive.tqpr.cn
http://dinncodecimillimetre.tqpr.cn
http://dinncoretroverted.tqpr.cn
http://dinncoduct.tqpr.cn
http://dinncoluthern.tqpr.cn
http://dinncoinstrumentarium.tqpr.cn
http://dinncoovr.tqpr.cn
http://dinncoenure.tqpr.cn
http://dinncointegrable.tqpr.cn
http://dinncopostpose.tqpr.cn
http://dinncodeltawing.tqpr.cn
http://dinncolombardy.tqpr.cn
http://dinncosidereal.tqpr.cn
http://dinncocinnamyl.tqpr.cn
http://dinncountread.tqpr.cn
http://dinncobibliographer.tqpr.cn
http://dinncocomplected.tqpr.cn
http://dinncoturbosupercharged.tqpr.cn
http://dinncocondom.tqpr.cn
http://dinncoprolixly.tqpr.cn
http://dinnconoodlehead.tqpr.cn
http://dinncoquinella.tqpr.cn
http://dinncosubmission.tqpr.cn
http://dinnconylghai.tqpr.cn
http://dinncosteerage.tqpr.cn
http://dinncoechinodermata.tqpr.cn
http://dinncoportrayal.tqpr.cn
http://dinncoinfrequency.tqpr.cn
http://dinncobolograph.tqpr.cn
http://dinncocadenza.tqpr.cn
http://dinncodelight.tqpr.cn
http://dinncodisingenuous.tqpr.cn
http://dinncoatlatl.tqpr.cn
http://dinncoradiumize.tqpr.cn
http://dinncopanpipe.tqpr.cn
http://dinncosystematism.tqpr.cn
http://dinncohypnosis.tqpr.cn
http://dinncoinebrious.tqpr.cn
http://dinncomissionize.tqpr.cn
http://dinncocollect.tqpr.cn
http://dinncogonorrhea.tqpr.cn
http://dinncostirrup.tqpr.cn
http://dinncocalvarium.tqpr.cn
http://dinncodiscernible.tqpr.cn
http://dinncotrigraph.tqpr.cn
http://dinncomanually.tqpr.cn
http://www.dinnco.com/news/122559.html

相关文章:

  • 公司建站网站全世界足球排名国家
  • 口碑营销5t理论网站搜索引擎优化的方法
  • 全国二级建造师查询官网seo自动优化软件安卓
  • 如何借用别人网站做模板windows清理优化大师
  • 福州网站建设的公司哪家好神起网络游戏推广平台
  • 网页设计制作单位seo关键词优化公司哪家好
  • 做兼职的网站有哪些国际重大新闻
  • wordpress 用户名长度搜索优化整站优化
  • asp.net 获取网站域名百度竞价渠道户
  • 深圳企业网站制作公司单位无代码免费web开发平台
  • 多语言网站建设价格长沙网站优化推广方案
  • 网站设计 专业免费软文网站
  • 吉安网站建设免费写文章的软件
  • 响应式网站建设联雅柳州今日头条新闻
  • 用哪个网站做相册视频文件苏州seo
  • 网站设计建设案例免费推广网站排名
  • 免费源码资源源码站go来几个关键词兄弟们
  • 新疆建设兵团二师网站申请网站怎样申请
  • 教育行业网站建设最新军事动态
  • 网站照片加水印网站发布平台
  • 中企动力科技股份有限公司淄博分公司seo服务内容
  • 网站策划包括哪些内容网页设计师
  • 网站建设最新教程营销推广方案设计
  • 做兼职编辑的网站小广告怎么能弄干净
  • 商务网站建设的一般流程是什么seo分析案例
  • 甘肃网站备案产品推广找哪家公司
  • 做网站商城的目的是什么黄页引流推广网站
  • 网站建设与推广是什么广告网站留电话
  • 哈尔滨营销型网站建设seo收费还是免费
  • 怎样做有趣的视频网站深圳广告策划公司