map+set
threebody_santi · · 算法·理论
set<int> st;//排序+去重#include<set> unordered_set<int> ust;//去重不排序#include<unordered_set> multiset <int> mst;//排序不去重 无头文件 int x; cin>>x; st.insert(x);//插入 st.erase(x,1)//从x位置删除1个 set<int>::iterator it; for(it=st.begin();it!=st.end;it++) { cout<<*it<<" "; }//遍历方法1 for(auto it=st.begin();it!=st.end;it++) { cout<<it<<" "; }//遍历方法2 for(auto x:st) { cout<<x<<" "; } st.find(x); //查找x //返回st.end()为不存在,存在返回指针 //从大到小排序,运用重载运算符修改< struct node { int x; bool operator<(const node b) const { return x>b.x; } } set<node> st; st.insert({x}); st.lower_bound(x); next_permutation();//全排列情况,例如:1,2,3,4 int a[]={1,2,3,4}; do { for(int i=0;i<5;i++) { cout<<a[i]<<" "; } cout<<endl; } while(next_permutation(a,a+4))//会输出1,2,4,3 ...... prev_permutation(a,a+4);//前一个全排列 lower_bound(st.begin(),st.end(),x);//第1个>=x的元素的地址 binary_search(st.begin(),st.end(),x);//查找是否有x upper_bound(st.begin(),st.end(),x);//第1个>x的元素的地址