hdu 1031 (partial sort problem, nth_element, stable_partition, lambda expression) 分类: hdoj 2015-06-15 17:47 26人阅读 评论(0) 收藏
partial sort.
first use std::nth_element to find pivot,
then use std::stable_partition with the pivot to partition the largest k, whose indices are in acsending order, print them in reverse order.
p.s. lambda expression is also used.
STL is powerful.
#include <cstdio>
#include <vector>
#include <algorithm>
struct IRPair{
int ind;
double rate;
};
int main() {
//freopen("input.txt","r",stdin);
int num_people, num_candidate, num_final, i,j;
double tmp;
std::vector<IRPair> vec;
std::vector<double> ratings;
while(scanf("%d%d%d",&num_people,&num_candidate,&num_final)!=EOF) {
vec.resize(num_candidate);
ratings.clear(); ratings.resize(num_candidate);
for(i=0;i<num_people;++i)
for(j=0;j<num_candidate;++j) { scanf("%lf",&tmp); ratings[j]+=tmp; }
for(i=0;i<num_candidate;++i) { vec[i].ind=i+1; vec[i].rate=ratings[i]; }
std::nth_element(&ratings[0],&ratings[num_candidate-num_final],&ratings[num_candidate]);
tmp=ratings[num_candidate-num_final];
std::stable_partition(&vec[0],&vec[num_candidate],[tmp](const IRPair &x) { return x.rate>=tmp; });
for(i=num_final-1;i>0;--i) { printf("%d ",vec[i].ind);}
printf("%d\n",vec[0].ind);
}
return 0;
}
156 ms for double, vector
140 ms for float, vector
140 ms for double, array
124 ms for float, arry
time for array / time for vector = 90%
版权声明:本文为博主原创文章,未经博主允许不得转载。// p.s. If in any way improment can be achieved, better performance or whatever, it will be well-appreciated to let me know, thanks in advance.
hdu 1031 (partial sort problem, nth_element, stable_partition, lambda expression) 分类: hdoj 2015-06-15 17:47 26人阅读 评论(0) 收藏的更多相关文章
- Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- The 3n + 1 problem 分类: POJ 2015-06-12 17:50 11人阅读 评论(0) 收藏
The 3n + 1 problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53927 Accepted: 17 ...
- Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1532 Drainage Ditches 分类: Brush Mode 2014-07-31 10:38 82人阅读 评论(0) 收藏
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- Codeforces 706C Hard problem 2016-09-28 19:47 90人阅读 评论(0) 收藏
C. Hard problem time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- hdu 1232, disjoint set, linked list vs. rooted tree, a minor but substantial optimization for path c 分类: hdoj 2015-07-16 17:13 116人阅读 评论(0) 收藏
three version are provided. disjoint set, linked list version with weighted-union heuristic, rooted ...
随机推荐
- SCCM日志存放路径
sccm有一些比较重要的日志大家可能经常需要查看.下面是一些比较常用的日志文件的存放位置. 客户端日志文件: 日志位于服务器端 SMS_CCM\Logs 文件夹中 日志位于客户端 %Windir%\S ...
- 【转】android fragment 博客 学习
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37970961 自从Fragment出现,曾经有段时间,感觉大家谈什么都能跟Fra ...
- Unity5 新功能解析--GI(全局光)
http://blog.csdn.net/leonwei/article/details/48009059 Unity5带来的最大的改变就是全新的GI,在烘焙引擎上抛弃了4的beast,使用了虚幻采用 ...
- Qt Charts
简述 Qt Charts模块提供了一套易于使用的图表组件.它采用了Qt Graphics View框架,因此图表可以很容易地集成到现代的用户界面. Qt Charts可以被用作QWidgets.QGr ...
- JAVA String作业——动手动脑以及课后实验性问题
一:如何解释这样的输出结果?从中你能总结出什么?1.源码 //mao2015.10.20 //==的两个分辨 //对原始数据而言 //对引用类型变量 public class StringPool { ...
- python中cPickle的用法
import cPickle as p f = file('data.txt' , 'w') data = (1 , 'A' , "hello") p.dump(data , f) ...
- java配置数据库连接池的方法步骤
java配置数据库连接池的方法步骤 java配置数据库连接池的方法步骤,需要的朋友可以参考一下 先来了解下什么是数据库连接池数据库连接池技术的思想非常简单,将数据库连接作为对象存储在一个Vecto ...
- js ——算法
1.使用js 数组去重复: 方法①: var arr=[1,2,1,5,2,3,5,1,6,9]; function deRepeat(){ var newArray=[]; var obj={}; ...
- dw添加emmet
1.emmet下载Emmet.zxp 2.怎么在dw中设置(命令->emmet->Expand Abbreviation)中查看使用emmet的快捷键,如果跟别人快捷键重合了 3.编辑-& ...
- 我们无法找到服务器加载工作簿的数据模型"的 SharePoint 网站,当您刷新 Excel 2013 工作簿中的数据透视表时出错
假定您使用 Analysis Services 源在 Microsoft Excel 2013 中创建数据透视表.将 Excel 工作簿上载到 Microsoft SharePoint 网站中.当您尝 ...