C++ nth_element greater
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <functional>
#include <iterator>
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;
copy(deq1.begin(), deq1.begin() + 5,ostream_iterator<int>(cout," "));
cout << endl;
cout << "------------------------------" << endl;
nth_element(deq1.begin(), deq1.end() - 5, deq1.end());
copy(deq1.end() - 5,deq1.end(), ostream_iterator<int>(cout, " "));
cout << endl;
cout << "------------------------------" << endl;
nth_element(deq1.begin(), deq1.begin() + 5,deq1.end(), greater<int>());
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
------------------------------
41 491 5705 6334 9961
------------------------------
24464 26500 26962 28145 29358
------------------------------
29358 28145 26962 26500 24464 23281 19169 18467 16827 15724 11478 9961 6334 5705 491 41
------------------------------
请按任意键继续. . .
C++ nth_element greater的更多相关文章
- nth_element学习
今天学习到STL中的nth_element,她是一个默认能求第k小的数的方法,需要的头文件为algorithm. 默认为:nth_element(start, start+n, end) 使第n大元素 ...
- STL_算法_依据第n个元素排序(nth_element)
C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) //全部容器适用 nth_element(b,n,e) nth_element(b,n,e,p) 对照:partition() ...
- 牛客2018多校第六场 J Heritage of skywalkert - nth_element
传送门 题意:提供一个随机生成函数,让你生成n个数,然后问你其中能找到的两个数的最小公倍数 最大 是多少. 思路:可以用nth_element()函数在O(n)下求出前 15 个大的数(当然,100个 ...
- 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)
链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...
- cb51a_c++_STL_算法_根据第n个元素排序nth_element
cb51a_c++_STL_算法_根据第n个元素排序nth_elementnth_element(b,n,e),比如最大的5个数排序,或者最小的几个数nth_element(b,n,e,p)对比:pa ...
- nth_element 测试程序
/******************************************************************** created: 2014/04/29 11:35 file ...
- Transform a BST to greater sum tree
Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater th ...
- R.java 文件内报错:Underscores can only be used with source level 1.7 or greater。
R.java 文件内报错:Underscores can only be used with source level 1.7 or greater 网上查找后得知是Android工程图片资源命名的问 ...
- Poj(2407),Greater New York Regional 2015 (D)
题目链接:http://poj.org/problem?id=2407 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
随机推荐
- javascript 给事件任务一个缓冲区
在编写前端的过程中,经常会监听事件并执行任务,我在这抛出2个比较常见的场景: 1.输入关键字搜索如果你监听input的chage事件,会有一个问题,在使用中文输入法时,你输入的几个拼音字母都会被触发我 ...
- Sonya and Exhibition
http://codeforces.com/group/1EzrFFyOc0/contest/1004/problem/B #include<iostream> #include<c ...
- 通过字节码分析this关键字以及异常表的重要作用
在之前的字节码分析中缺少对异常的介绍,这次主要来对字节码异常表相关的东东进行一个学习,下面先来编写一个相关异常的小程序: 接着编译来看用javap -verbose来查看一下它的字节码信息: xion ...
- MVVM框架-MVVMLight
项目URL:http://www.mvvmlight.net/ 一.安装MVVMLight 在NuGet程序包中搜索MVVMLight,然后安装. 二.使用 安装完MVVMLight后项目中会自动生成 ...
- goroutine 修改全局变量无效问题
原文:https://studygolang.com/topics/7050 go修改全局变量的问题 测试 goroutine 修改全局变量,有x y 两个全局函数,分别在两个 goroutine f ...
- Docker:18.x版本安装与卸载
Docker CE 分为 stable, test, 和 nightly 三个更新频道.每六个月发布一个 stable 版本 初始化机器 #1.关闭警报 vi /etc/inputrc #然后将set ...
- Matlab step方法
在Matlab中我们经常能看到Java的影子,即面向对象编程(Object Oriented Programming,OOP). 以Turbo编码为例: hTEnc = comm.TurboEncod ...
- Codeforces Round #495 (Div. 2) A,B,C
A题 1.新添加一间酒店,要求酒店离已有的最近的一间酒店的距离恰好等于d 2.最左和最右必定存在合适的两种情况 3.酒店之间的情况就要判断两间酒店间的距离: 小于2d,表示无法在这两间酒店中间找到合适 ...
- vue+axios+elementUI文件上传与下载
vue+axios+elementUI文件上传与下载 Simple_Learn 关注 0.5 2018.05.30 10:20 字数 209 阅读 15111评论 4喜欢 6 1.文件上传 这里主要 ...
- fixed 失效
1. 父元素设置 transform 属性后, 会导致 position: fixed 失效. 2. 设置以下属性也会影响 fixed 属性. -webkit-perspective: 1000; - ...