HDU 1425 sort 【哈希入门】
2015-03-04 23:34
351 查看
题意:给出n个数,输出前m大的数
和上一题一样,将输入的数加上一个极大地值作为地址
View Code
果断用sort超时了= =
和上一题一样,将输入的数加上一个极大地值作为地址
#include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<algorithm> using namespace std; typedef long long LL; const int M=500000; int a,hash[M*2+5]; int main() { int n,m,i,j; while(scanf("%d %d",&n,&m)!=EOF){ memset(hash,0,sizeof(hash)); for(i=1;i<=n;i++){ scanf("%d",&a); hash[a+M]=1;//防止负数的下标 } for(i=2*M;m>0;i--){ if(hash[i]) { if(m!=1) printf("%d ",i-M); else printf("%d\n",i-M); m--; } } } return 0; }
View Code
果断用sort超时了= =
相关文章推荐
- HDU1425:sort(哈希思想!)
- hdu 1425 sort ---- hash入门
- hdu_1425_sort ( hash 入门 )
- HDU 1425 ( sort )
- HDU 1425 sort
- HDU-1425sort
- hdu 1425 sort (基数排序)
- hdu 1425 sort 解题报告
- HDU 1425 sort hash+加速输入
- HDU 1425 sort
- 哈希表学习小记 Hdu 1280+1425+3785 (前m大数)(简单哈希)
- 哈希表入门题目总结(HDU 1280、1425、2027、3833、1496、2648 POJ 1200)
- HDU 1425 sort
- HDU 1425 sort
- hdu 1425 sort用堆排序做的
- hdu 1425 sort
- HDU 1425 sort
- hdu 1425 sort
- hdu 1425 sort
- hdu_1425 sort