哈希算法:Sort
            
            
                    
                        标签:http   alt   efi   sort函数   algo   需要   info   printf   nlogn   

 
 
如果用sort函数的话需要nlogn的时间复杂度
#include
#includestring.h>
#include
#include
#includestring.h>
#define OFFSET 500000 
int Hash[1000001];
int main()
{
    int n, m;
    while (scanf_s("%d%d", &n, &m) != EOF)
    {
        for (int i = -500000; i 500000; i++)
            Hash[i + OFFSET] = 0;
        for (int i = 1; i )
        {
            int x;
            scanf_s("%d", &x);
            Hash[x + OFFSET] = 1;
        }
        for (int i = 500000; i >= -500000; i--)
        {
            if (Hash[i + OFFSET] == 1)
            {
                printf("%d", i);
                m--;
                if (m != 0)
                    printf(" ");
                else
                {
                    printf("\n");
                    break;
                }
            }
        }
    }
    return 0;
}
 
 
哈希算法:Sort
标签:http   alt   efi   sort函数   algo   需要   info   printf   nlogn   
原文地址:https://www.cnblogs.com/bestluna/p/14473432.html
                    
             
            
            
            
            
                
                    文章来自:
搜素材网的
编程语言模块,转载请注明文章出处。
                    文章标题:
哈希算法:Sort
                    文章链接:http://soscw.com/index.php/essay/92960.html                
 
             
            
                                
评论