您的位置:首页 > 其它

hdu 1425 sort

2010-05-23 23:39 344 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1425

一小心就会超时,这题我是时分深刻,

用hash吧

#include<iostream>
using namespace std;
int
hash[1000001];
int
main()
{

int
i,n,m,t;
while
(scanf("%d%d",&n,&m)!=EOF)
{

memset(hash,0,sizeof(hash));
i=n;
while
(i--)
{

scanf("%d",&t);
hash[500000+t]++;
}

for
(i=1000000;i>=0&&m>0;)
{

if
(hash[i]>0)
{

m--;
hash[i]--;
if
(m==0)
cout<<i-500000<<endl;
else

cout<<i-500000<<" ";
}

else

{

i--;
}
}
}

return
0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: