10亿个浮点数,求出其中最大的10000个.
来源:互联网 发布:mac ae2017中英文切换 编辑:程序博客网 时间:2024/05/16 21:31
#include "stdafx.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional> // for greater<>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<float> bigs(10000,0);
vector<float>::iterator it;
// Init vector data
for (it = bigs.begin(); it != bigs.end(); it++)
{
*it = (float)rand()/7; // random values;
}
cout << bigs.size() << endl;
make_heap(bigs.begin(),bigs.end(), greater<float>()); // The first one is the smallest one!
float ff;
for (int i = 0; i < 1000000000; i++)
{
ff = (float) rand() / 7;
if (ff > bigs.front()) // replace the first one ?
{
// set the smallest one to the end!
pop_heap(bigs.begin(), bigs.end(), greater<float>());
// remove the last/smallest one
bigs.pop_back();
// add to the last one
bigs.push_back(ff);
// mask heap again, the first one is still the smallest one
push_heap(bigs.begin(),bigs.end(),greater<float>());
}
}
// sort by ascent
sort_heap(bigs.begin(), bigs.end(), greater<float>());
// sort by descent
//sort_heap(bigs.begin(), bigs.end());
//sort_heap(bigs.begin(), bigs.end(), less<float>());
return 0;
}
- 10亿个浮点数,求出其中最大的10000个.
- 10亿个浮点数,求出其中最大的10000个. .
- 编写算法,从10亿个浮点数当中,选出其中最大的10000个
- 从10亿个浮点数当中,选出其中最大的10000个
- 输出10个数字,求出其中第二大的数
- Java编程 有1亿个浮点数,请找出其中对大的10000个
- 有10亿个浮点数,从中找出1万个最大的数。
- 有10亿个浮点数,从中找出1万个最大的数。
- 有10亿个浮点数,从中找出1万个最大的数。
- 面试-从10亿个浮点数中找出最大的1万个
- [转]从10亿个浮点数中找出最大的1万个
- 面试-从10亿个浮点数中找出最大的1万个
- 从10亿个浮点数中找出最大的1万个
- 有10亿个浮点数,找出一万个最大的数
- 找出N个浮点数中最大的k个不同的浮点数
- 给定若干个四位数,求出其中满足以下条件的数的个数
- Linux-C基础知识学习:C语言作业-输入10个整数,输出其中最大的数
- 输入10个数,将其中最小的数与第一个对换,最大的数与最后一个对换
- NDK全称 Native Development Kit
- 不再神秘:苹果背后的10位精英设计师
- windows 下远程登录ubuntu服务器--realVNC
- C++ 关于声明,定义,类的定义,头文件作用,防止头文件在同一个编译单元重复引用,不具名空间
- easyUI 格式化ComboBox
- 10亿个浮点数,求出其中最大的10000个.
- H264码流的打包发送(以live555为例)
- Spring,hibernate,struts的面试笔试题(含答案)
- ZKW费用流的研究
- ibatis中井号跟美元符号区别(#、$)
- ireport解决中文乱码问题
- Java使用Arrays、ArrayList、LinkedList、Vector实现插入查询性能分析
- shell script里面的美元符号什么时候该用
- Spring MVC拦截器的配置