一:pair的基本用法
在一些问题里,常常需要将两种数据捆绑处理,除了利用结构体的方式外还可以利用STL里面的pair函数
他也可以作为map函数的键值,来进行数据处理。
第一种用法:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    pair<int,int>p1,p2;//定义数据类型 
    pair<int,int>pp(1,2);//定义之后直接赋值 
    p1=make_pair(1,2);//利用make_pair函数赋值 
    p2.first=3;
    p2.second=-1;//直接对数据赋值 
    printf("%d %d\n",p1.first,p2.second);    
    printf("%d",pp.second);//输出测试 
    return 0;
}

第二种用法:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    pair<string,int>p1,p2;//定义数据类型 
    map<string,int>mp;
    mp.insert(make_pair("hello",3));//将键值添加到map里 
    mp.insert(pair<string,int>("yes",1));
    printf("%d\n",mp["yes"]);
    map<string,int>::iterator it=mp.begin();//使用迭代器指代容器 
    cout<<it->first<<" "<<it->second<<"\n";
    //疑问:如何找到mp的最后一个数据 
    return 0;
}

补充:
1:swap函数:交换两个容器里的数据

pair<int,int>p,p1;
p.swap(p1); 

2:头文件 pair函数需要在#include<utility>下使用
头文件#include<map>下也可以使用</map></utility>

3该容器可以构成数组结构

#include<bits/stdc++.h>
using namespace std;
const int maxn=10;
int main()
{
    pair<int,int>p[maxn];//定义pair数组
    p[0].first=1;
    p[1].second=2;
    printf("%d\n",p[1].first);//调用pair数组
    return 0;
}

4该容器可以作为其他容器的基本单元
例如栈,队列等

#include<bits/stdc++.h>
using namespace std;
const int maxn=10;
int main()
{
    pair<int,int>p;
    stack<pair<int,int> >st;//注意这里的构造
    p.first=1;
    p.second=2;
    st.push(p);
    printf("%d\n",st.top().first);
    return 0;
}

二:用于实现二分法的函数
lower_bound(a.begin(),a.end(),x)-a
(减去a可得到对应位置的下标)
返回第一个大于或等于搜索数的位置

uper_bound(a.begin(),a.end(),x)-a
返回第一个大于搜索数的位置

三:iterator 迭代器
迭代器(Iterator)是一种对象,它能够用来遍历标准模板库容器中的部分或全部元素,每个迭代器对象代表容器中的确定的地址。
通俗点说,迭代器表现的像指针,读取集合或者数组中的一个值,读完以后又指向下一条数据,一个个数过去。