各类c++的stl库

55 篇文章 0 订阅
15 篇文章 0 订阅

acwing算法基本的数据结构(三)

/*
vector,变长数组,倍增的思想
    size()元素个数
    empty()判断是否为空
    clear()清空
    front()/back()
    push_back()/pop_back()
    begin()/end()
    []
    支持比较运算,按字典序
 

pair<int,int>
    first,第一个元素
    second,第二个元素
    支持比较运算,以first为第一关键字,以second为第二关键字(字典序)

string,字符串,substr(),c_str()
    size()length()都是返回字符串长度
    empty()
    clear()
    push()
    front()
    back()
    pop()
    substr()
 
queue,队列,
    push(),front(),pop()
    
 
priority_queue,优先队列,默认大根堆
    push(),top(),pop()
    小根堆:priority_queue<int,vector<int>,greater<int> >heap;

stack,栈,push(),top(),pop()
deque,双端队列
    size()
    empty()
    clear()
    front()
    back()
    push_back()/pop_back()
    push_front()/pop_front()
    begin()/end()
    []
 
set,map,multiset,multimap,基于平衡二叉树(红黑树),动态维护有序序列
    size()
    empty()
    clear()
    begin()/end() ++,-- 返回前驱和后继,时间复杂度O(logn)
 
 
    set/multiset (set不支持重复会自动忽略,multiset支持重复)
        insert()插入一个数  注意multiset的insert会有个默认返回地址迭代,可以直接赋值,set没有
        find()查找一个数,没找到返回就返回end
        count()返回某一个数的个数
        erase()
            (1)输入是一个数x,删除所有x,O(k+logn)
            (2)输入是一个迭代器,删除这个迭代器
        lower_bound()/upper_bound()
            lower_bound(x)返回大于等于x的最小的数的迭代器
            upper_bound(x)返回大于x的最小的数的迭代器
    map/multimap
        insert()  插入的数是一个pair
        erase() 输入的参数是pair或者迭代器
        find()
        [] 时间复杂度是O(logn)
        lower_bound()/upper_bound()

unordered_set,unordered_map,unordered_multiset,unordered_multimap,哈希表
    和上面类似,绝大部分操作的时间复杂度是O(1)
    不支持lower_bound()/upper_bound(),不支持迭代器++,--
bitset,压位
    bitset<100000>s;
    ~,&,|,^
    >>,<<
    ==,!=
    []
    count()返回有多少个1
    any/none()
    any()判断是否至少有一个1
    none()判断是否全为空
 
    set(),把所有位置成1
    set(k,v)将第k位变成v
    reset()把所有位变成0
    flip()等价于~
    flip(k)把第k位取反
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>a;
    for(int i=0;i<10;i++)a.push_back(i);
    for(int i=0;i<a.size();i++)cout<<a[i]<<' ';
    cout<<endl;
    for(vector<int>::iterator i=a.begin();i!=a.end();i++)
        cout<<*i<<" ";
    cout<<endl;
    for(auto x:a)cout<<x<<" ";
    cout<<endl;
    
    pair<int,string>p;
    p=make_pair(10,"wyt");
    cout<<p.first<<" "<<p.second<<endl;
    p={20,"abc"};
    cout<<p.first<<" "<<p.second<<endl;
    
    string b="wyt";
    b+="f";
    cout<<b<<endl;
    cout<<b.substr(1,2)<<endl;
    
    unordered_map<string,int>c;
    c["aaa"]=123;
    cout<<c["aaa"]<<endl;
    
    bitset<1000>s;
    s[1]=1;
    cout<<s.none()<<endl;
}
 

make_pair

#include<bits/stdc++.h>
using namespace std;
pair<int,int>q;
pair<int,int>p[10];
int main(){
    q=make_pair(2,3);
    p[1]={4,5};
    cout<<q.first<<" "<<q.second<<endl;
    cout<<p[1].first<<" "<<p[1].second<<endl;
}


离散化

    sort(alls.begin(),alls.end());
    alls.erase(unique(alls.begin(),alls.end()),alls.end());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值