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 ...
随机推荐
- Linux常用命令及文件管理
Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示. 目录解释: .代表此层目录: .. 代表父目录:-代表前一个目录:~代表是家目录. (1)ls命令(显示) -a:列出所有文 ...
- Codeforces 567D - One-Dimensional Battle Ships - [树状数组+二分]
题目链接:https://codeforces.com/problemset/problem/567/D 题意: 在一个 $1 \times n$ 的网格上,初始摆放着 $k$ 只船,每只船的长度均为 ...
- 牛客算法:DNA序列
import java.util.*; public class Main{ public static void main(String[] args){ try(Scanner in = new ...
- 存储过程:SET Transaction Isolation Level Read语法的四种情况
这几天一直在弄存储过程,现在在这里跟大伙共享下资料: SET Transaction Isolation Level Read UNCOMMITTED 使用这句东东呢可以分为四种情况,现在就在这里逐一 ...
- GEF中TreeViewer的叶子节点展开
/** * GEF树叶子节点的展开 * @param items */ private void expand(TreeItem[] items) { for (int i = 0; i < i ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) B2. TV Subscriptions (Hard Version)
链接: https://codeforces.com/contest/1247/problem/B2 题意: The only difference between easy and hard ver ...
- [ES2019] Use JavaScript ES2019 flatMap to Map and Filter an Array
ES2019 introduces the Array.prototype.flatMap method. In this lesson, we'll investigate a common use ...
- 题解 [ZJOI2010]基站选址
题解 [ZJOI2010]基站选址 题面 解析 首先考虑一个暴力的DP, 设\(f[i][k]\)表示第\(k\)个基站设在第\(i\)个村庄,且不考虑后面的村庄的最小费用. 那么有\(f[i][k] ...
- 003_linux驱动之_file_operations函数
(一)解析file_operations函数 解析002_linux驱动之_register_chrdev注册字符设备中的问题 (二) 1. file_operations结构原型 2. 使用举例 ...
- [Luogu] 可持久化线段树 1(主席树)
https://www.luogu.org/problemnew/show/P3834 #include<cstdio> #include<iostream> #include ...