HDOJ 1425 sort

超级传送门:

http://acm.hdu.edu.cn/showproblem.php?pid=1425


此题的特点:数据量大,但是数据的范围不大。用hash就行,hash函数就是减500000

#include<stdio.h>
int hash[1000100]={0};
int main () {
    int n,m,i,a,count,max,first;
    while (scanf("%d%d",&n,&m) != EOF) {
        count = 0;
        first = 1;
        max = -500000;
        for (i=0;i<n;i++) {
            scanf("%d",&a);
            if (a>max) max = a;
            hash[a+500000] = 1;
        }
        for (i=max+500000;i>=0;i--) {
            if (count>=m) break;
            if (hash[i]) {
                if (first) first = 0;
                else printf(" ");
                printf("%d",i-500000);
                count++;
            }
        }
        printf("\n");
    }
    return 0;
}


你可能感兴趣的:(ini)