cb33a_c++_STL_算法_查找算法_(6)binary_search_includes
cb33a_c++_STL_算法_查找算法_(6)binary_search_includes
//针对已序区间的查找算法,如set,multiset关联容器-自动排序
binary_search(b,e,v),begin,end,value--返回bool,不会告诉具体找到的位置。只能找一个
if (binary_search(iset.begin(), iset.end(), 5))//返回bool
binary_search(b,e,v,p) begin,end, value,parameter(谓词)
includes(b,e,sb,se)--begin,end,second begin,second end.可以找多个,不连续的。查找对象必须是排序的,顺序存放的数据。
if(includes(iset.begin(),iset.end(),search.begin(),search.end()))
include (b,e,sb,se,p)--p,parameter,谓词
lower_bound()--找到后,可以返回位置
/*cb33a_c++_STL_算法_查找算法_(6)binary_search_includes
//针对已序区间的查找算法,如set,multiset关联容器-自动排序
binary_search(b,e,v),begin,end,value--返回bool,不会告诉具体找到的位置。只能找一个
if (binary_search(iset.begin(), iset.end(), 5))//返回bool
binary_search(b,e,v,p) begin,end, value,parameter(谓词) includes(b,e,sb,se)--begin,end,second begin,second end.可以找多个,不连续的。查找对象必须是排序的,顺序存放的数据。
if(includes(iset.begin(),iset.end(),search.begin(),search.end()))
include (b,e,sb,se,p)--p,parameter,谓词 lower_bound()--找到后,可以返回位置
*/ #include <iostream>
#include <algorithm>
#include <list>
#include <set>
#include <vector> using namespace std; int main()
{
list<int> ilist;
for (int i = ; i <= ; ++i)
ilist.insert(ilist.end(), i);//从后面插入
ilist.push_back();
set<int> iset;
for (int ii = ; ii <= ; ++ii)
iset.insert(iset.end(), ii);
iset.insert(iset.end(),);//即使在最后插入的0,它也会自动排序,0会移动到最前面的 for (list<int>::iterator iter = ilist.begin(); iter != ilist.end(); ++iter)
cout << *iter << ' ';
cout << endl;
cout << "set容器结果查看" << endl;
for (set<int>::iterator iter = iset.begin(); iter != iset.end(); ++iter)
cout << *iter << ' ';
cout << endl; if (binary_search(iset.begin(), iset.end(), ))//返回bool
cout << "找到了" << endl;
else
cout << "没找到" << endl; vector<int> search; //
search.push_back();
search.push_back();
search.push_back();
if(includes(iset.begin(),iset.end(),search.begin(),search.end()))
cout<<"iset里面找 search vector的,3,4,7。同时都找到了"<<endl;
//只要包含 3,4,7,就算找到了
//注意,vector如果没有顺序排放,就会出错的。3,7,4就不可以。
//已序区间,就是已经排序的区域。默认排序的,或者自动排序的容器
else
cout << "没找到" << endl; return ;
}
cb33a_c++_STL_算法_查找算法_(6)binary_search_includes的更多相关文章
- cb34a_c++_STL_算法_查找算法_(7)_lower_bound
cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...
- cb32a_c++_STL_算法_查找算法_(5)adjacent_find
cb32a_c++_STL_算法_查找算法_(5)adjacent_findadjacent_find(b,e),b,begin(),e,end()adjacent_find(b,e,p),p-par ...
- cb31a_c++_STL_算法_查找算法_(4)find_first_of
cb31a_c++_STL_算法_查找算法_(4)find_first_offind_first_of(b,e,sb,se),sb,second begin, se,second end();find ...
- cb30a_c++_STL_算法_查找算法_(3)search_find_end
cb30a_c++_STL_算法_查找算法_(3)search_find_endsearch()pos = search(ideq.begin(), ideq.end(), ilist.begin() ...
- cb29a_c++_STL_算法_查找算法_(2)search_n
cb29a_c++_STL_算法_查找算法_(2)search_n//比如:连续查找连续的n个8search_n(b,e,c,v),迭代器b,begin(),e,end().连续的c个vpos=sea ...
- cb28a_c++_STL_算法_查找算法_(1)find_find_if
cb28a_c++_STL_算法_查找算法_(1)find_find_iffind() //线性查找,比较慢.pos1 = find(ilist.begin(), ilist.end(), 5);fi ...
- STL_算法_查找算法(lower_bound、upper_bound、equal_range)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n))) 已序区间查找算法 lower_bound() //找第一个符合的 ...
- STL_算法_查找算法(find、find_if)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...
- STL_算法_查找算法(binary_search、includes)
C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n))) 已序区间查找算法 binary_search //二分查 ...
随机推荐
- Unity中激活子物体
void GetChildrenAndSetActive() { Transform[] imageTargetObjects = GetComponentsInChildren<Transfo ...
- Jmeter(四) - 从入门到精通 - 创建网络测试计划(详解教程)
1.简介 在本节中,您将学习如何创建基本的 测试计划来测试网站.您将创建五个用户,这些用户将请求发送到JMeter网站上的两个页面.另外,您将告诉用户两次运行测试.因此,请求总数为(5个用户)x(2个 ...
- BUUCTF WEB-WP(3)
BUUCTF WEB 几道web做题的记录 [ACTF2020 新生赛]Exec 知识点:exec命令执行 这题最早是在一个叫中学生CTF平台上看到的类似,比这题稍微要复杂一些,多了一些限制(看看大佬 ...
- JS代码静态分析及挖掘
JavaScript 已经成为现代 Web 浏览器开发中最普遍的技术之一.使用客户端 JavaScript 框架(如 AngularJS,ReactJS 和 Vue.js)构建的应用程序已向前端输送了 ...
- 经典卷积神经网络算法(3):VGG
.caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...
- PowerPC-MPC56xx Flash模式启动过程
https://mp.weixin.qq.com/s/SpBOfzJJ1OizYP-rsLJVqQ Flash启动模式为最常用模式. 一般情况下,芯片上电之后,从flash起始位置读取第一条指令的 ...
- 50个SQL语句(MySQL版) 问题二十
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- 重装ArchLinux后修改GRUB配置不生效问题的解决
重装ArchLinux后修改GRUB配置不生效问题的解决 mount指令看一下挂载,或者vim /etc/fstab看一下有没有/boot,看看fstab是不是没写进去.... 我特喵昨天重装完Arc ...
- Web 三维组态的仿真运用案例:民航飞机的数据监控
前言 在飞机航行的过程中,客舱里座位上方的荧屏上,除了播放电视剧和广告之外,还会时不时的切换到一个飞机航行的监控系统.这个监控系统的主要目的是,让乘客可以了解到飞机在航行过程中的整体状况.距离目的地的 ...
- Java实现 蓝桥杯 算法提高 上帝造题五分钟
算法提高 上帝造题五分钟 时间限制:1.0s 内存限制:256.0MB 问题描述 第一分钟,上帝说:要有题.于是就有了L,Y,M,C 第二分钟,LYC说:要有向量.于是就有了长度为n写满随机整数的向量 ...