hdoj-1425-sort
Problem Description
给你n个整数,请按从大到小的顺序输出其中前m大的数。
Input
每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-500000,500000]的整数。
Output
对每组测试数据按从大到小的顺序输出前m大的数。
Sample Input
5 3
3 -35 92 213 -644
Sample Output
213 92 3
//hd-1425-ac
#include<iostream>
# define offset 500000
bool hash[offset+500001];
int main(){
int n,m,temp;
while(scanf("%d%d",&n,&m)!=EOF){
memset(hash,false,sizeof(hash));
for(int i=0;i<n;i++){
scanf("%d",&temp);
hash[temp+offset]=true;
}
for(int i=1000000;i>=0&&m>0;i--)
if(hash[i]){
if(m==1) printf("%d\n",i-offset);
else printf("%d ",i-offset);
m--;
}
}
return 0;
}
简单哈希-hdoj-1425-sort,布布扣,bubuko.com
原文:http://blog.csdn.net/chuchus/article/details/23661013