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;
}
一小心就会超时,这题我是时分深刻,
用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;
}
相关文章推荐
- hdu 1425 sort (水题,计数法)
- hdu_1425_sort ( hash 入门 )
- HDU 1425 sort
- HDU-#1425 sort(Hash散列)
- hdu 1425:sort(排序,经典题。快排模板)
- HDU 1425 sort (hash)
- sort (HDU_1425) 快速排序
- HDU-1425sort
- HDU 1425 sort hash+加速输入
- HDU - 1425 sort
- HDU 1425 sort 题解
- HDU 1425 sort
- hdu1425 sort (朴素)
- hdu 1425 sort 解题报告
- 堆排序练习 hdu 1425 sort
- hdu 1425 sort
- HDU 1425 sort
- HDU 1425 sort 题解
- HDU 1425 sort hash+加速输入
- HDU 1425 sort