Next_permutation(a,a+n) 字典序的下一个

1、  lower_bound:返回有序数组中第一个大于等于查找值的位置

例:int p=lower_bound(a,a+n,x)-a;(从a数组中查找第一个大于等于x的元素下标)

2、  upper_bound:返回有序数组中第一个大于查找值的位置

例:int p=upper_bound(a,a+n,x)-a;(从a数组中查找第一个大于x的元素下标)

3、  set集合

特点:每个元素最多出现一次,默认从小到大排好序。

创建:空对象:set<int>a;

      带比较准则的空对象:

struct cmp

{

          bool operator()(int a,int b)

          {

              return a>b;

          }

};

set<int,cmp>a;

利用set对象s1拷贝生成s2:set<int> s2(s1);

插入:a.insert(1);

删除:a.erase(1);

清空:a.clear();

计数:a.count(1);

读取长度:a.size();

查找:a.find();

找到返回该值位置,否则返回最后一个元素后面一个位置(越界).

set<int>::iterator it;

it=s.find(5);

if(it!=s.end()) cout<<*it<<endl;

a.lower_bound(); a.upper_bound();可用

测试是否为空:a.empty();

首尾元素:a.begin(); a.end();

          for(set<int>::iterator it=a.begin();it!=a.end();it++)

4、  map映射

特点:默认升序排序。

创建:map<int,string> a;

添加:a[1]=”ANSWER”;

查找:map<int,string>::iterator it

      it=a.find(1);

if(it!=a.end()) 成功;

删除:查找成功后a.erase(it);

读取长度:a.size();

清空:a.clear();

测试是否为空:a.empty();

首尾元素:a.begin(); a.end();

          for(set<int>::iterator it=a.begin();it!=a.end();it++)

a.lower_bound(); a.upper_bound();可用

5、priority_queue优先队列

   特点:默认从大到小排序

   改变优先级:priority_queue<int,vector<int>,greater<int> > q;(从小到大)

   struct node

{

       int a,b,c;

       bool operator < (const node &a) const

       {

           return a>a.a||(a==a.a&&b>a.b);

       }

};