HDU1425:sort

来源:互联网 发布:linux arm 交叉编译 编辑:程序博客网 时间:2024/05/16 07:15

hash原来做过

<pre name="code" class="cpp">#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int M  = 1000001;#define MIN -99999999bool hashh[M];void init(){    for(int i=0;i<M;i++) hashh[i]=false;}int main(){    int n,m,maxn;    while(scanf("%d%d",&n,&m)!=EOF){        int p;        init();        maxn = MIN;        for(int i=0;i<n;i++)        {            scanf("%d",&p);            p += 500000;            hashh[p]=true;            if(p>maxn) maxn = p;        }        printf("%d",maxn  - 500000);        if(--m){            for(int i=maxn  - 1; i>= 0; --i){                if(hashh[i]){                    printf(" %d",i-500000);                    --m;                    if(!m) break;                }            }        }        puts("");    }    return 0;}



0 0
原创粉丝点击