#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

int main()
{
  deque<int> deq1;
  deque<int>::iterator deq_iter1;

  for (int k=0;k<16;k++)
  {
    deq1.push_back(rand());
  }

  for (deq_iter1 = deq1.begin();deq_iter1 != deq1.end();++deq_iter1)
  {
    cout << *deq_iter1 << " ";
  }
  cout << endl;
  cout << "------------------------------"<<endl;

  nth_element(deq1.begin(), deq1.begin() + 5, deq1.end());
  for (deq_iter1 = deq1.begin(); deq_iter1 != deq1.end(); ++deq_iter1)
  {
    cout << *deq_iter1 << " ";
  }
  cout << endl;
  cout << "------------------------------" << endl;

  system("pause");
  return 0;
}

===================================

41 18467 6334 26500 19169 15724 11478 29358 26962 24464 5705 28145 23281 16827 9961 491
------------------------------
41 491 5705 6334 9961 11478 15724 16827 18467 19169 23281 24464 26500 26962 28145 29358
------------------------------
请按任意键继续. . .

C++ STL nth_element的更多相关文章

  1. 深海中的STL—nth_element

    如果让你求区间第\(k\)大,你会怎么做呢? 主席树?确实是个不错的选择(不过像我这种垃圾还是乖乖打暴力吧) 在c++的stl库中,提供了nth_element这样一个函数 它的用法是nth_elem ...

  2. hdu 6040 Hints of sd0061(stl: nth_element(arr,arr+k,arr+n))

    Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  3. c++ stl nth_element 原理解析

    nth_element是stl中的一个库函数,它会使迭代器nth所指的元素与整个[first,last)完整排序后.同一个位置的元素同值.即找到完整排序时第n位的正确值. 但这个函数与完整排序的区别在 ...

  4. 题解 UVA11300 【Spreading the Wealth】

    环形均分纸牌问题应该不少人都很熟悉了,而且题解区写的也比较全了...... 我这篇题解主要是介绍一个新的STL--nth_element 以及解答几个其他题解里面有应用但是没有注释的问题.(比如说我第 ...

  5. USACO 刷题记录bzoj

    bzoj 1606: [Usaco2008 Dec]Hay For Sale 购买干草——背包 #include<cstdio> #include<cstring> #incl ...

  6. 18级北航软件学院算法复习--Samshui

    A 比特手链 简单模拟 判断 贪心 叶姐要想哥赠送一串比特手链,这个手链由0和1组成.想哥买了手链B,无意间得知叶姐想要同样长度的手链A.想哥囊中羞涩,只能手工调整手链.他希望最少通过以下操作进行最少 ...

  7. STL 源码分析《2》----nth_element() 使用与源码分析

    Select 问题: 在一个无序的数组中 找到第 n 大的元素. 思路 1: 排序,O(NlgN) 思路 2: 利用快排的 RandomizedPartition(), 平均复杂度是 O(N) 思路 ...

  8. STL中的nth_element()方法的使用

    STL中的nth_element()方法的使用 通过调用nth_element(start, start+n, end) 方法可以使第n大元素处于第n位置(从0开始,其位置是下标为 n的元素),并且比 ...

  9. STL之nth_element()(取容器中的第n大值)

    nth_element()函数 头文件:#include<algorithm> 作用:nth_element作用为求第n大的元素,并把它放在第n位置上,下标是从0開始计数的,也就是说求第0 ...

随机推荐

  1. openssl/opensslv.h错误的解决方案

    sudo apt install libssl-dev  

  2. airtest使用

    airtest Airtest是网易开发的手机UI界面自动化测试工具 通过截图功能操作手机虽然方便,但是截图涉及到分辨率的问题,代码不能在不同的手机上通用. 可以用来开发手机App爬虫 使用先抓大再抓 ...

  3. webpack4.0打包优化策略整理小结

    本文转载于:https://www.jb51.net/article/137449.htm 介绍了webpack4.0打包优化策略整理小结,分享给大家,具体如下: webapck4 新特性介绍-参考资 ...

  4. easyUI-filebox图片上传和预览

    转载自:https://blog.csdn.net/nvxiaq/article/details/77740516 备注: 1.如需上传多个图片可定义多个change_photo函数 在onChang ...

  5. 2019牛客多校第五场 generator 1——广义斐波那契循环节&&矩阵快速幂

    理论部分 二次剩余 在数论中,整数 $X$ 对整数 $p$ 的二次剩余是指 $X^2$ 除以 $p$ 的余数. 当存在某个 $X$,使得式子 $X^2 \equiv d(mod \ p)$ 成立时,称 ...

  6. 洛谷P2279 消防局的设立【树形dp】

    题目:https://www.luogu.org/problemnew/show/P2279 题意:一棵树.在节点处建消防站,可以覆盖与他距离在2之内的节点.问最少要建多少个消防站,可以覆盖所有的节点 ...

  7. Codeforces Round #584 B. Koala and Lights

    链接: https://codeforces.com/contest/1209/problem/B 题意: It is a holiday season, and Koala is decoratin ...

  8. AtCoder Beginner Contest 116 C题 【题意:可以在任意区间【L,R】上加1,求通过最少加1次数得到题目给定的区间】】{思维好题}

    C - Grand Garden In a flower bed, there are NN flowers, numbered 1,2,......,N1,2,......,N. Initially ...

  9. 设计模式--UML类图简介

    UML:Unified Modelling Language是一种统一建模语言(英语:Unified Modeling Language,缩写 UML)是非专利的第三代建模和规约语言. “+”表示pu ...

  10. Ubuntu 在VirtualBox里无法联网【已解决】

    1. 在virtualBox中设置网络:设置->网络->将连接方式选定为“网络地址转换(NAT)” 点确定 2.进入Ubuntu系统中:系统设置->网络, 在弹出的对话框中选择:有线 ...