zoukankan      html  css  js  c++  java
  • STL算法

    头文件:<algorithm>

    sort  快速排序   stable_sort  稳定快速排序  O(n log n)

      sort(iterator_begin,iterator_end); //iterator_指迭代器位置

      sort(iterator_begin,iterator_end,cmp); //cmp为自定义排序

    reverse  翻转  O(n)

      reverse(iterator_begin,iterator_end);

    unique  去重(返回新范围尾部迭代器)  O(n)

      int len=unique(iterator_begin,iterator_end)-iterator_begin; //得到新范围长度

    lower_bound/upper_bound  二分查找  O(log n)

        int pos1=lower_bound(iterator_begin,iterator_end,x)-iterator_begin;
        //第一个大于等于x的元素位置
        int pos2=upper_bound(iterator_begin,iterator_end,x)-iterator_begin;
        //第一个大于x的元素位置
        int pos3=lower_bound(iterator_begin,iterator_end,x,greater<int>())-iterator_begin;
        //第一个小于等于x的元素位置
        int pos4=upper_bound(iterator_begin,iterator_end,x,greater<int>())-iterator_begin;
        //第一个小于x的元素位置

    next_permutation  下一个排列  O(n)

        //字典序输出1~n的全排列 
        for(int i=1;i<=n;i++)
            a[i]=i;
        do{
            for(int i=1;i<n;i++)
                printf("%d ",a[i]);
            printf("%d
    ",a[n]);
        }while(next_permutation(a+1,a+n+1));
  • 相关阅读:
    洛谷提高组比赛day2
    清北合肥day2-day5
    高精度开根
    清北合肥day1
    愤怒的小鸟
    蓝书图论题
    替罪羊树&&非旋treap
    【bzoj4811】[Ynoi2017]由乃的OJ 树链剖分+线段树区间合并
    【bzoj3866】The Romantic Hero dp
    【bzoj3747】[POI2015]Kinoman
  • 原文地址:https://www.cnblogs.com/Pedesis/p/10350332.html
Copyright © 2011-2022 走看看