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的更多相关文章

  1. cb34a_c++_STL_算法_查找算法_(7)_lower_bound

    cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...

  2. 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 ...

  3. 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 ...

  4. cb30a_c++_STL_算法_查找算法_(3)search_find_end

    cb30a_c++_STL_算法_查找算法_(3)search_find_endsearch()pos = search(ideq.begin(), ideq.end(), ilist.begin() ...

  5. 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 ...

  6. cb28a_c++_STL_算法_查找算法_(1)find_find_if

    cb28a_c++_STL_算法_查找算法_(1)find_find_iffind() //线性查找,比较慢.pos1 = find(ilist.begin(), ilist.end(), 5);fi ...

  7. STL_算法_查找算法(lower_bound、upper_bound、equal_range)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n)))    已序区间查找算法 lower_bound()        //找第一个符合的 ...

  8. STL_算法_查找算法(find、find_if)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...

  9. STL_算法_查找算法(binary_search、includes)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n)))     已序区间查找算法 binary_search             //二分查 ...

随机推荐

  1. [计划任务 - dos]制作任务工具

    语法 schtasks /create /tn TaskName /tr TaskRun /sc schedule [/mo modifier] [/d day] [/m month[,month.. ...

  2. 2017-ICLR-NAS_with_RL-Neural Architecture Search with Reinforcement Learning-论文阅读

    NAS with RL 2017-ICLR-Neural Architecture Search with Reinforcement Learning Google Brain Quoc V . L ...

  3. python脚本:在Ubuntu16系统上基于xtrabackup2.4和mysql5.7实现数据库数据的自动化备份和恢复,亲测有效!

    1 安装教程 官网安装教程:https://www.percona.com/doc/percona-xtrabackup/2.4/installation/apt_repo.html -------- ...

  4. 数据库之 MySQL --- 下载、安装 及 概述(一)

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 一 . MySql数据库的安装 1.图解MySQL程序结构 ​ 2.双击运行安装程序:以Win32位为例 ...

  5. Java实现 蓝桥杯VIP 算法训练 简单加法

    时间限制:1.0s 内存限制:512.0MB 问题描述 首先给出简单加法算式的定义: 如果有一个算式(i)+(i+1)+(i+2),(i>=0),在计算的过程中,没有任何一个数位出现了进位,则称 ...

  6. Java实现 LeetCode 279 完全平方数

    279. 完全平方数 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, -)使得它们的和等于 n.你需要让组成和的完全平方数的个数最少. 示例 1: 输入: n = 12 输出: ...

  7. Java实现 LeetCode 190 颠倒二进制位

    190. 颠倒二进制位 颠倒给定的 32 位无符号整数的二进制位. 示例 1: 输入: 00000010100101000001111010011100 输出: 0011100101111000001 ...

  8. Java实现 LeetCode 171 Excel表列序号

    171. Excel表列序号 给定一个Excel表格中的列名称,返回其相应的列序号. 例如, A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> ...

  9. 第六届蓝桥杯JavaB组省赛真题

    解题代码部分来自网友,如果有不对的地方,欢迎各位大佬评论 题目1.三角形面积 题目描述 如图1所示.图中的所有小方格面积都是1. 那么,图中的三角形面积应该是多少呢? 请填写三角形的面积.不要填写任何 ...

  10. java实现SPFA算法

    1 问题描述 何为spfa(Shortest Path Faster Algorithm)算法? spfa算法功能:给定一个加权连通图,选取一个顶点,称为起点,求取起点到其它所有顶点之间的最短距离,其 ...